Some changes to migrate towards C++ and a multithreaded model

This commit is contained in:
ridiculousfish 2011-12-26 19:18:46 -08:00
parent 3f16ace678
commit 8d2f107d61
90 changed files with 7368 additions and 5981 deletions

View file

@ -0,0 +1,348 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXFileReference section */
D0A0850313B3ACEE0099B651 /* builtin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = builtin.h; sourceTree = "<group>"; };
D0A0850413B3ACEE0099B651 /* common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = "<group>"; };
D0A0850513B3ACEE0099B651 /* complete.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = complete.h; sourceTree = "<group>"; };
D0A0850613B3ACEE0099B651 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
D0A0850713B3ACEE0099B651 /* env_universal_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = env_universal_common.h; sourceTree = "<group>"; };
D0A0850813B3ACEE0099B651 /* env_universal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = env_universal.h; sourceTree = "<group>"; };
D0A0850913B3ACEE0099B651 /* env.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = env.h; sourceTree = "<group>"; };
D0A0850A13B3ACEE0099B651 /* event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = event.h; sourceTree = "<group>"; };
D0A0850B13B3ACEE0099B651 /* exec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = exec.h; sourceTree = "<group>"; };
D0A0850C13B3ACEE0099B651 /* expand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = expand.h; sourceTree = "<group>"; };
D0A0850D13B3ACEE0099B651 /* fallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fallback.h; sourceTree = "<group>"; };
D0A0850E13B3ACEE0099B651 /* function.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = function.h; sourceTree = "<group>"; };
D0A0850F13B3ACEE0099B651 /* halloc_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = halloc_util.h; sourceTree = "<group>"; };
D0A0851013B3ACEE0099B651 /* halloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = halloc.h; sourceTree = "<group>"; };
D0A0851113B3ACEE0099B651 /* highlight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = highlight.h; sourceTree = "<group>"; };
D0A0851213B3ACEE0099B651 /* history.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = history.h; sourceTree = "<group>"; };
D0A0851313B3ACEE0099B651 /* input_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = input_common.h; sourceTree = "<group>"; };
D0A0851413B3ACEE0099B651 /* input.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = input.h; sourceTree = "<group>"; };
D0A0851513B3ACEE0099B651 /* intern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = intern.h; sourceTree = "<group>"; };
D0A0851613B3ACEE0099B651 /* io.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = io.h; sourceTree = "<group>"; };
D0A0851713B3ACEE0099B651 /* iothread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iothread.h; sourceTree = "<group>"; };
D0A0851813B3ACEE0099B651 /* kill.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = kill.h; sourceTree = "<group>"; };
D0A0851913B3ACEE0099B651 /* mimedb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mimedb.h; sourceTree = "<group>"; };
D0A0851A13B3ACEE0099B651 /* output.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = output.h; sourceTree = "<group>"; };
D0A0851B13B3ACEE0099B651 /* parse_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parse_util.h; sourceTree = "<group>"; };
D0A0851C13B3ACEE0099B651 /* parser_keywords.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parser_keywords.h; sourceTree = "<group>"; };
D0A0851D13B3ACEE0099B651 /* parser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parser.h; sourceTree = "<group>"; };
D0A0851E13B3ACEE0099B651 /* path.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = path.h; sourceTree = "<group>"; };
D0A0851F13B3ACEE0099B651 /* print_help.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = print_help.h; sourceTree = "<group>"; };
D0A0852013B3ACEE0099B651 /* proc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = proc.h; sourceTree = "<group>"; };
D0A0852113B3ACEE0099B651 /* reader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reader.h; sourceTree = "<group>"; };
D0A0852213B3ACEE0099B651 /* sanity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sanity.h; sourceTree = "<group>"; };
D0A0852313B3ACEE0099B651 /* screen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = screen.h; sourceTree = "<group>"; };
D0A0852413B3ACEE0099B651 /* signal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = signal.h; sourceTree = "<group>"; };
D0A0852513B3ACEE0099B651 /* tokenizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tokenizer.h; sourceTree = "<group>"; };
D0A0852613B3ACEE0099B651 /* util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = util.h; sourceTree = "<group>"; };
D0A0852713B3ACEE0099B651 /* wgetopt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wgetopt.h; sourceTree = "<group>"; };
D0A0852813B3ACEE0099B651 /* wildcard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wildcard.h; sourceTree = "<group>"; };
D0A0852913B3ACEE0099B651 /* wutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wutil.h; sourceTree = "<group>"; };
D0A0852A13B3ACEE0099B651 /* xdgmime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xdgmime.h; sourceTree = "<group>"; };
D0A0852B13B3ACEE0099B651 /* xdgmimealias.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xdgmimealias.h; sourceTree = "<group>"; };
D0A0852C13B3ACEE0099B651 /* xdgmimeglob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xdgmimeglob.h; sourceTree = "<group>"; };
D0A0852D13B3ACEE0099B651 /* xdgmimeint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xdgmimeint.h; sourceTree = "<group>"; };
D0A0852E13B3ACEE0099B651 /* xdgmimemagic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xdgmimemagic.h; sourceTree = "<group>"; };
D0A0852F13B3ACEE0099B651 /* xdgmimeparent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xdgmimeparent.h; sourceTree = "<group>"; };
D0A0853013B3ACEE0099B651 /* builtin_commandline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = builtin_commandline.cpp; sourceTree = "<group>"; };
D0A0853113B3ACEE0099B651 /* builtin_complete.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = builtin_complete.cpp; sourceTree = "<group>"; };
D0A0853213B3ACEE0099B651 /* builtin_jobs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = builtin_jobs.cpp; sourceTree = "<group>"; };
D0A0853313B3ACEE0099B651 /* builtin_set.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = builtin_set.cpp; sourceTree = "<group>"; };
D0A0853413B3ACEE0099B651 /* builtin_ulimit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = builtin_ulimit.cpp; sourceTree = "<group>"; };
D0A0853513B3ACEE0099B651 /* builtin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = builtin.cpp; sourceTree = "<group>"; };
D0A0853613B3ACEE0099B651 /* common.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = common.cpp; sourceTree = "<group>"; };
D0A0853713B3ACEE0099B651 /* complete.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = complete.cpp; sourceTree = "<group>"; };
D0A0853813B3ACEE0099B651 /* env_universal_common.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = env_universal_common.cpp; sourceTree = "<group>"; };
D0A0853913B3ACEE0099B651 /* env_universal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = env_universal.cpp; sourceTree = "<group>"; };
D0A0853A13B3ACEE0099B651 /* env.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = env.cpp; sourceTree = "<group>"; };
D0A0853B13B3ACEE0099B651 /* event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = event.cpp; sourceTree = "<group>"; };
D0A0853C13B3ACEE0099B651 /* exec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = exec.cpp; sourceTree = "<group>"; };
D0A0853D13B3ACEE0099B651 /* expand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = expand.cpp; sourceTree = "<group>"; };
D0A0853E13B3ACEE0099B651 /* fallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fallback.cpp; sourceTree = "<group>"; };
D0A0853F13B3ACEE0099B651 /* fish_indent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fish_indent.cpp; sourceTree = "<group>"; };
D0A0854013B3ACEE0099B651 /* fish_pager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fish_pager.cpp; sourceTree = "<group>"; };
D0A0854113B3ACEE0099B651 /* fish_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fish_tests.cpp; sourceTree = "<group>"; };
D0A0854213B3ACEE0099B651 /* fish.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fish.cpp; sourceTree = "<group>"; };
D0A0854313B3ACEE0099B651 /* fishd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fishd.cpp; sourceTree = "<group>"; };
D0A0854413B3ACEE0099B651 /* function.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = function.cpp; sourceTree = "<group>"; };
D0A0854513B3ACEE0099B651 /* halloc_util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = halloc_util.cpp; sourceTree = "<group>"; };
D0A0854613B3ACEE0099B651 /* halloc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = halloc.cpp; sourceTree = "<group>"; };
D0A0854713B3ACEE0099B651 /* highlight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = highlight.cpp; sourceTree = "<group>"; };
D0A0854813B3ACEE0099B651 /* history.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = history.cpp; sourceTree = "<group>"; };
D0A0854913B3ACEE0099B651 /* input_common.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = input_common.cpp; sourceTree = "<group>"; };
D0A0854A13B3ACEE0099B651 /* input.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = input.cpp; sourceTree = "<group>"; };
D0A0854B13B3ACEE0099B651 /* intern.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = intern.cpp; sourceTree = "<group>"; };
D0A0854C13B3ACEE0099B651 /* io.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = io.cpp; sourceTree = "<group>"; };
D0A0854D13B3ACEE0099B651 /* iothread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = iothread.cpp; sourceTree = "<group>"; };
D0A0854E13B3ACEE0099B651 /* key_reader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = key_reader.cpp; sourceTree = "<group>"; };
D0A0854F13B3ACEE0099B651 /* kill.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = kill.cpp; sourceTree = "<group>"; };
D0A0855013B3ACEE0099B651 /* mimedb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mimedb.cpp; sourceTree = "<group>"; };
D0A0855113B3ACEE0099B651 /* output.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = output.cpp; sourceTree = "<group>"; };
D0A0855213B3ACEE0099B651 /* parse_util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parse_util.cpp; sourceTree = "<group>"; };
D0A0855313B3ACEE0099B651 /* parser_keywords.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parser_keywords.cpp; sourceTree = "<group>"; };
D0A0855413B3ACEE0099B651 /* parser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parser.cpp; sourceTree = "<group>"; };
D0A0855513B3ACEE0099B651 /* path.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = path.cpp; sourceTree = "<group>"; };
D0A0855613B3ACEE0099B651 /* print_help.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = print_help.cpp; sourceTree = "<group>"; };
D0A0855713B3ACEE0099B651 /* proc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = proc.cpp; sourceTree = "<group>"; };
D0A0855813B3ACEE0099B651 /* reader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reader.cpp; sourceTree = "<group>"; };
D0A0855913B3ACEE0099B651 /* sanity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sanity.cpp; sourceTree = "<group>"; };
D0A0855A13B3ACEE0099B651 /* screen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = screen.cpp; sourceTree = "<group>"; };
D0A0855B13B3ACEE0099B651 /* set_color.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = set_color.cpp; sourceTree = "<group>"; };
D0A0855C13B3ACEE0099B651 /* signal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = signal.cpp; sourceTree = "<group>"; };
D0A0855D13B3ACEE0099B651 /* tokenizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tokenizer.cpp; sourceTree = "<group>"; };
D0A0855E13B3ACEE0099B651 /* util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = util.cpp; sourceTree = "<group>"; };
D0A0855F13B3ACEE0099B651 /* wgetopt.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wgetopt.cpp; sourceTree = "<group>"; };
D0A0856013B3ACEE0099B651 /* wildcard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wildcard.cpp; sourceTree = "<group>"; };
D0A0856113B3ACEE0099B651 /* wutil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wutil.cpp; sourceTree = "<group>"; };
D0A0856213B3ACEE0099B651 /* xdgmime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xdgmime.cpp; sourceTree = "<group>"; };
D0A0856313B3ACEE0099B651 /* xdgmimealias.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xdgmimealias.cpp; sourceTree = "<group>"; };
D0A0856413B3ACEE0099B651 /* xdgmimeglob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xdgmimeglob.cpp; sourceTree = "<group>"; };
D0A0856513B3ACEE0099B651 /* xdgmimeint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xdgmimeint.cpp; sourceTree = "<group>"; };
D0A0856613B3ACEE0099B651 /* xdgmimemagic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xdgmimemagic.cpp; sourceTree = "<group>"; };
D0A0856713B3ACEE0099B651 /* xdgmimeparent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xdgmimeparent.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXGroup section */
D0A084F013B3AC130099B651 = {
isa = PBXGroup;
children = (
D0A0850313B3ACEE0099B651 /* builtin.h */,
D0A0853013B3ACEE0099B651 /* builtin_commandline.cpp */,
D0A0853113B3ACEE0099B651 /* builtin_complete.cpp */,
D0A0853213B3ACEE0099B651 /* builtin_jobs.cpp */,
D0A0853313B3ACEE0099B651 /* builtin_set.cpp */,
D0A0853413B3ACEE0099B651 /* builtin_ulimit.cpp */,
D0A0853513B3ACEE0099B651 /* builtin.cpp */,
D0A0850413B3ACEE0099B651 /* common.h */,
D0A0853613B3ACEE0099B651 /* common.cpp */,
D0A0850513B3ACEE0099B651 /* complete.h */,
D0A0853713B3ACEE0099B651 /* complete.cpp */,
D0A0850613B3ACEE0099B651 /* config.h */,
D0A0850713B3ACEE0099B651 /* env_universal_common.h */,
D0A0853813B3ACEE0099B651 /* env_universal_common.cpp */,
D0A0850813B3ACEE0099B651 /* env_universal.h */,
D0A0853913B3ACEE0099B651 /* env_universal.cpp */,
D0A0850913B3ACEE0099B651 /* env.h */,
D0A0853A13B3ACEE0099B651 /* env.cpp */,
D0A0850A13B3ACEE0099B651 /* event.h */,
D0A0853B13B3ACEE0099B651 /* event.cpp */,
D0A0850B13B3ACEE0099B651 /* exec.h */,
D0A0853C13B3ACEE0099B651 /* exec.cpp */,
D0A0850C13B3ACEE0099B651 /* expand.h */,
D0A0853D13B3ACEE0099B651 /* expand.cpp */,
D0A0850D13B3ACEE0099B651 /* fallback.h */,
D0A0853E13B3ACEE0099B651 /* fallback.cpp */,
D0A0850E13B3ACEE0099B651 /* function.h */,
D0A0854413B3ACEE0099B651 /* function.cpp */,
D0A0853F13B3ACEE0099B651 /* fish_indent.cpp */,
D0A0854013B3ACEE0099B651 /* fish_pager.cpp */,
D0A0854113B3ACEE0099B651 /* fish_tests.cpp */,
D0A0854213B3ACEE0099B651 /* fish.cpp */,
D0A0854313B3ACEE0099B651 /* fishd.cpp */,
D0A0850F13B3ACEE0099B651 /* halloc_util.h */,
D0A0851013B3ACEE0099B651 /* halloc.h */,
D0A0854613B3ACEE0099B651 /* halloc.cpp */,
D0A0854513B3ACEE0099B651 /* halloc_util.cpp */,
D0A0851113B3ACEE0099B651 /* highlight.h */,
D0A0854713B3ACEE0099B651 /* highlight.cpp */,
D0A0851213B3ACEE0099B651 /* history.h */,
D0A0854813B3ACEE0099B651 /* history.cpp */,
D0A0851313B3ACEE0099B651 /* input_common.h */,
D0A0854913B3ACEE0099B651 /* input_common.cpp */,
D0A0851413B3ACEE0099B651 /* input.h */,
D0A0854A13B3ACEE0099B651 /* input.cpp */,
D0A0851513B3ACEE0099B651 /* intern.h */,
D0A0854B13B3ACEE0099B651 /* intern.cpp */,
D0A0851613B3ACEE0099B651 /* io.h */,
D0A0854C13B3ACEE0099B651 /* io.cpp */,
D0A0851713B3ACEE0099B651 /* iothread.h */,
D0A0854D13B3ACEE0099B651 /* iothread.cpp */,
D0A0851813B3ACEE0099B651 /* kill.h */,
D0A0854F13B3ACEE0099B651 /* kill.cpp */,
D0A0854E13B3ACEE0099B651 /* key_reader.cpp */,
D0A0851913B3ACEE0099B651 /* mimedb.h */,
D0A0855013B3ACEE0099B651 /* mimedb.cpp */,
D0A0851A13B3ACEE0099B651 /* output.h */,
D0A0855113B3ACEE0099B651 /* output.cpp */,
D0A0851B13B3ACEE0099B651 /* parse_util.h */,
D0A0855213B3ACEE0099B651 /* parse_util.cpp */,
D0A0851C13B3ACEE0099B651 /* parser_keywords.h */,
D0A0855313B3ACEE0099B651 /* parser_keywords.cpp */,
D0A0851D13B3ACEE0099B651 /* parser.h */,
D0A0855413B3ACEE0099B651 /* parser.cpp */,
D0A0851E13B3ACEE0099B651 /* path.h */,
D0A0855513B3ACEE0099B651 /* path.cpp */,
D0A0851F13B3ACEE0099B651 /* print_help.h */,
D0A0855613B3ACEE0099B651 /* print_help.cpp */,
D0A0852013B3ACEE0099B651 /* proc.h */,
D0A0855713B3ACEE0099B651 /* proc.cpp */,
D0A0852113B3ACEE0099B651 /* reader.h */,
D0A0855813B3ACEE0099B651 /* reader.cpp */,
D0A0852213B3ACEE0099B651 /* sanity.h */,
D0A0855913B3ACEE0099B651 /* sanity.cpp */,
D0A0852313B3ACEE0099B651 /* screen.h */,
D0A0855A13B3ACEE0099B651 /* screen.cpp */,
D0A0852413B3ACEE0099B651 /* signal.h */,
D0A0855C13B3ACEE0099B651 /* signal.cpp */,
D0A0855B13B3ACEE0099B651 /* set_color.cpp */,
D0A0852513B3ACEE0099B651 /* tokenizer.h */,
D0A0855D13B3ACEE0099B651 /* tokenizer.cpp */,
D0A0852613B3ACEE0099B651 /* util.h */,
D0A0855E13B3ACEE0099B651 /* util.cpp */,
D0A0852713B3ACEE0099B651 /* wgetopt.h */,
D0A0855F13B3ACEE0099B651 /* wgetopt.cpp */,
D0A0852813B3ACEE0099B651 /* wildcard.h */,
D0A0856013B3ACEE0099B651 /* wildcard.cpp */,
D0A0852913B3ACEE0099B651 /* wutil.h */,
D0A0856113B3ACEE0099B651 /* wutil.cpp */,
D0A0852A13B3ACEE0099B651 /* xdgmime.h */,
D0A0856213B3ACEE0099B651 /* xdgmime.cpp */,
D0A0852B13B3ACEE0099B651 /* xdgmimealias.h */,
D0A0856313B3ACEE0099B651 /* xdgmimealias.cpp */,
D0A0852C13B3ACEE0099B651 /* xdgmimeglob.h */,
D0A0856413B3ACEE0099B651 /* xdgmimeglob.cpp */,
D0A0852D13B3ACEE0099B651 /* xdgmimeint.h */,
D0A0856513B3ACEE0099B651 /* xdgmimeint.cpp */,
D0A0852E13B3ACEE0099B651 /* xdgmimemagic.h */,
D0A0856613B3ACEE0099B651 /* xdgmimemagic.cpp */,
D0A0852F13B3ACEE0099B651 /* xdgmimeparent.h */,
D0A0856713B3ACEE0099B651 /* xdgmimeparent.cpp */,
);
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXLegacyTarget section */
D0A084F713B3AC130099B651 /* FishsFish */ = {
isa = PBXLegacyTarget;
buildArgumentsString = "-f Makefile.cpp -k ${ACTION}";
buildConfigurationList = D0A084FA13B3AC130099B651 /* Build configuration list for PBXLegacyTarget "FishsFish" */;
buildPhases = (
);
buildToolPath = /usr/bin/make;
buildWorkingDirectory = "";
dependencies = (
);
name = FishsFish;
passBuildSettingsInEnvironment = 1;
productName = FishsFish;
};
/* End PBXLegacyTarget section */
/* Begin PBXProject section */
D0A084F213B3AC130099B651 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
};
buildConfigurationList = D0A084F513B3AC130099B651 /* Build configuration list for PBXProject "FishsFish" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = D0A084F013B3AC130099B651;
projectDirPath = "";
projectRoot = "";
targets = (
D0A084F713B3AC130099B651 /* FishsFish */,
);
};
/* End PBXProject section */
/* Begin XCBuildConfiguration section */
D0A084F813B3AC130099B651 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.6;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
D0A084F913B3AC130099B651 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.6;
SDKROOT = macosx;
};
name = Release;
};
D0A084FB13B3AC130099B651 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
DEBUGGING_SYMBOLS = YES;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
D0A084FC13B3AC130099B651 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
D0A084F513B3AC130099B651 /* Build configuration list for PBXProject "FishsFish" */ = {
isa = XCConfigurationList;
buildConfigurations = (
D0A084F813B3AC130099B651 /* Debug */,
D0A084F913B3AC130099B651 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
D0A084FA13B3AC130099B651 /* Build configuration list for PBXLegacyTarget "FishsFish" */ = {
isa = XCConfigurationList;
buildConfigurations = (
D0A084FB13B3AC130099B651 /* Debug */,
D0A084FC13B3AC130099B651 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = D0A084F213B3AC130099B651 /* Project object */;
}

View file

@ -162,13 +162,13 @@ static void builtin_wperror( const wchar_t *s)
{
if( s != 0 )
{
sb_append( sb_err, s, L": ", (void *)0 );
sb_append( sb_err, s, L": ", NULL );
}
char *err = strerror( errno );
wchar_t *werr = str2wcs( err );
if( werr )
{
sb_append( sb_err, werr, L"\n", (void *)0 );
sb_append( sb_err, werr, L"\n", NULL );
free( werr );
}
}
@ -401,11 +401,11 @@ static void builtin_missing_argument( const wchar_t *cmd, const wchar_t *opt )
*/
#include "builtin_set.c"
#include "builtin_commandline.c"
#include "builtin_complete.c"
#include "builtin_ulimit.c"
#include "builtin_jobs.c"
#include "builtin_set.cpp"
#include "builtin_commandline.cpp"
#include "builtin_complete.cpp"
#include "builtin_ulimit.cpp"
#include "builtin_jobs.cpp"
/**
List all current key bindings
@ -868,7 +868,7 @@ static int builtin_block( wchar_t **argv )
{
block_t *block=current_block;
event_block_t *eb = malloc( sizeof( event_block_t ) );
event_block_t *eb = (event_block_t *)malloc( sizeof( event_block_t ) );
if( !eb )
DIE_MEM();
@ -999,7 +999,7 @@ static int builtin_builtin( wchar_t **argv )
sb_append( sb_out,
el,
L"\n",
(void *)0 );
NULL );
}
al_destroy( &names );
}
@ -1160,19 +1160,19 @@ static void functions_def( wchar_t *name, string_buffer_t *out )
sb_append( out,
L"function ",
name,
(void *)0);
NULL);
if( desc && wcslen(desc) )
{
wchar_t *esc_desc = escape( desc, 1 );
sb_append( out, L" --description ", esc_desc, (void *)0 );
sb_append( out, L" --description ", esc_desc, NULL );
free( esc_desc );
}
if( !function_get_shadows( name ) )
{
sb_append( out, L" --no-scope-shadowing", (void *)0 );
sb_append( out, L" --no-scope-shadowing", NULL );
}
for( i=0; i<al_get_count( &ev); i++ )
@ -1423,7 +1423,7 @@ static int builtin_functions( wchar_t **argv )
sb_append( &buff,
al_get(&names, i),
L", ",
(void *)0 );
NULL );
}
write_screen( (wchar_t *)buff.buff, sb_out );
@ -1436,7 +1436,7 @@ static int builtin_functions( wchar_t **argv )
sb_append( sb_out,
al_get(&names, i),
L"\n",
(void *)0 );
NULL );
}
}
@ -1629,7 +1629,7 @@ static int builtin_function( wchar_t **argv )
break;
}
e = halloc( current_block, sizeof(event_t));
e = (event_t *)halloc( current_block, sizeof(event_t));
if( !e )
DIE_MEM();
e->type = EVENT_SIGNAL;
@ -1653,7 +1653,7 @@ static int builtin_function( wchar_t **argv )
break;
}
e = halloc( current_block, sizeof(event_t));
e = (event_t *)halloc( current_block, sizeof(event_t));
e->type = EVENT_VARIABLE;
e->param1.variable = halloc_wcsdup( current_block, woptarg );
@ -1667,7 +1667,7 @@ static int builtin_function( wchar_t **argv )
{
event_t *e;
e = halloc( current_block, sizeof(event_t));
e = (event_t *)halloc( current_block, sizeof(event_t));
e->type = EVENT_GENERIC;
e->param1.param = halloc_wcsdup( current_block, woptarg );
@ -1683,7 +1683,7 @@ static int builtin_function( wchar_t **argv )
wchar_t *end;
event_t *e;
e = halloc( current_block, sizeof(event_t));
e = (event_t *)halloc( current_block, sizeof(event_t));
if( !e )
DIE_MEM();
@ -1864,7 +1864,7 @@ static int builtin_function( wchar_t **argv )
}
sb_append( sb_err,
nxt, L" ", (void *)0 );
nxt, L" ", NULL );
}
al_destroy( &names );
sb_append( sb_err, L"\n" );
@ -1874,7 +1874,7 @@ static int builtin_function( wchar_t **argv )
}
else
{
function_data_t * d = halloc( current_block, sizeof( function_data_t ));
function_data_t * d = (function_data_t *)halloc( current_block, sizeof( function_data_t ));
d->name=halloc_wcsdup( current_block, name);
d->description=desc?halloc_wcsdup( current_block, desc):0;
@ -2021,13 +2021,13 @@ static int builtin_read( wchar_t **argv )
{
wchar_t *buff=0;
int i, argc = builtin_count_args( argv );
wchar_t *ifs;
const wchar_t *ifs;
int place = ENV_USER;
wchar_t *nxt;
wchar_t *prompt = DEFAULT_READ_PROMPT;
wchar_t *commandline = L"";
const wchar_t *prompt = DEFAULT_READ_PROMPT;
const wchar_t *commandline = L"";
int exit_res=STATUS_BUILTIN_OK;
wchar_t *mode_name = READ_MODE_NAME;
const wchar_t *mode_name = READ_MODE_NAME;
int shell = 0;
woptind=0;
@ -2686,7 +2686,7 @@ static int builtin_cd( wchar_t **argv )
{
sb_append( sb_err,
parser_current_line(),
(void *)0 );
NULL );
}
res = 1;
@ -2718,7 +2718,7 @@ static int builtin_cd( wchar_t **argv )
{
sb_append( sb_err,
parser_current_line(),
(void *)0 );
NULL );
}
res = 1;
@ -2848,7 +2848,7 @@ static int builtin_source( wchar_t ** argv )
argc = builtin_count_args( argv );
wchar_t *fn;
const wchar_t *fn;
const wchar_t *fn_intern;
@ -2892,7 +2892,7 @@ static int builtin_source( wchar_t ** argv )
else
{
fn_intern = intern(fn);
free( fn );
free( (void *)fn );
}
}
@ -3838,7 +3838,7 @@ void builtin_init()
for( i=0; builtin_data[i].name; i++ )
{
hash_put( &builtin, builtin_data[i].name, builtin_data[i].func );
hash_put( &builtin, builtin_data[i].name, (void *)builtin_data[i].func );
intern_static( builtin_data[i].name );
}
}
@ -3923,7 +3923,7 @@ const wchar_t *builtin_get_desc( const wchar_t *b )
if( !desc )
{
int i;
desc = malloc( sizeof( hash_table_t ) );
desc = (hash_table_t *)malloc( sizeof( hash_table_t ) );
if( !desc)
return 0;
@ -3947,8 +3947,8 @@ void builtin_push_io( int in )
al_push( &io_stack, sb_err );
}
builtin_stdin = in;
sb_out = malloc(sizeof(string_buffer_t));
sb_err = malloc(sizeof(string_buffer_t));
sb_out = (string_buffer_t *)malloc(sizeof(string_buffer_t));
sb_err = (string_buffer_t *)malloc(sizeof(string_buffer_t));
sb_init( sb_out );
sb_init( sb_err );
}

View file

@ -148,7 +148,7 @@ static void write_part( const wchar_t *begin,
tokenizer tok;
string_buffer_t out;
wchar_t *buff;
int pos;
size_t pos;
pos = get_cursor_pos()-(begin-get_buffer());
@ -171,7 +171,7 @@ static void write_part( const wchar_t *begin,
case TOK_STRING:
{
wchar_t *tmp = unescape( tok_last( &tok ), UNESCAPE_INCOMPLETE );
sb_append( &out, tmp, L"\n", (void *)0 );
sb_append( &out, tmp, L"\n", NULL );
free( tmp );
break;
}
@ -258,7 +258,7 @@ static int builtin_commandline( wchar_t **argv )
sb_append( sb_err,
argv[0],
L": Can not set commandline in non-interactive mode\n",
(void *)0 );
NULL );
builtin_print_help( argv[0], sb_err );
return 1;
}
@ -489,7 +489,7 @@ static int builtin_commandline( wchar_t **argv )
sb_append( sb_err,
argv[0],
L": Too many arguments\n",
(void *)0 );
NULL );
builtin_print_help( argv[0], sb_err );
return 1;
}

View file

@ -26,7 +26,7 @@ Functions used for implementing the complete builtin.
/**
Internal storage for the builtin_get_temporary_buffer() function.
Internal storage for the builtin_complete_get_temporary_buffer() function.
*/
static const wchar_t *temporary_buffer;
@ -132,7 +132,7 @@ static void builtin_complete_add( array_list_t *cmd,
for( i=0; i<al_get_count( cmd ); i++ )
{
builtin_complete_add2( al_get( cmd, i ),
builtin_complete_add2( (const wchar_t *)al_get( cmd, i ),
COMMAND,
short_opt,
gnu_opt,
@ -145,7 +145,7 @@ static void builtin_complete_add( array_list_t *cmd,
if( authoritative != -1 )
{
complete_set_authoritative( al_get( cmd, i ),
complete_set_authoritative( (const wchar_t *)al_get( cmd, i ),
COMMAND,
authoritative );
}
@ -154,7 +154,7 @@ static void builtin_complete_add( array_list_t *cmd,
for( i=0; i<al_get_count( path ); i++ )
{
builtin_complete_add2( al_get( path, i ),
builtin_complete_add2( (const wchar_t *)al_get( path, i ),
PATH,
short_opt,
gnu_opt,
@ -167,7 +167,7 @@ static void builtin_complete_add( array_list_t *cmd,
if( authoritative != -1 )
{
complete_set_authoritative( al_get( path, i ),
complete_set_authoritative( (const wchar_t *)al_get( path, i ),
PATH,
authoritative );
}
@ -280,6 +280,7 @@ static void builtin_complete_remove( array_list_t *cmd,
const wchar_t *builtin_complete_get_temporary_buffer()
{
ASSERT_IS_MAIN_THREAD();
return temporary_buffer;
}
@ -290,6 +291,7 @@ const wchar_t *builtin_complete_get_temporary_buffer()
*/
static int builtin_complete( wchar_t **argv )
{
ASSERT_IS_MAIN_THREAD();
int res=0;
int argc=0;
int result_mode=SHARED;
@ -299,7 +301,7 @@ static int builtin_complete( wchar_t **argv )
string_buffer_t short_opt;
array_list_t gnu_opt, old_opt;
wchar_t *comp=L"", *desc=L"", *condition=L"";
const wchar_t *comp=L"", *desc=L"", *condition=L"";
wchar_t *do_complete = 0;
@ -561,7 +563,7 @@ static int builtin_complete( wchar_t **argv )
for( i=0; i<al_get_count( comp ); i++ )
{
completion_t *next = (completion_t *)al_get( comp, i );
wchar_t *prepend;
const wchar_t *prepend;
if( next->flags & COMPLETE_NO_CASE )
{

View file

@ -101,7 +101,7 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
L"\t",
j->command,
L"\n",
(void *)0 );
NULL );
break;
}

View file

@ -188,7 +188,7 @@ static int parse_index( array_list_t *indexes,
const wchar_t *name,
int var_count )
{
int len;
size_t len;
int count = 0;
const wchar_t *src_orig = src;
@ -282,14 +282,14 @@ static int update_values( array_list_t *list,
one-based, but the array_list_t uses zero-based indices
*/
long ind = al_get_long(indexes, i) - 1;
void *new = (void *) al_get(values, i);
const wchar_t *newv = (const wchar_t*) al_get(values, i);
if( ind < 0 )
{
return 1;
}
free((void *) al_get(list, ind));
al_set(list, ind, new != 0 ? wcsdup(new) : wcsdup(L""));
al_set(list, ind, newv != 0 ? wcsdup(newv) : wcsdup(L""));
}
return 0;
@ -387,7 +387,7 @@ static void print_variables(int include_values, int esc, int scope)
e_value = esc ? expand_escape_variable(value) : wcsdup(value);
sb_append(sb_out, L" ", e_value, (void *)0);
sb_append(sb_out, L" ", e_value, NULL);
free(e_value);
if( shorten )
@ -469,7 +469,7 @@ static int builtin_set( wchar_t **argv )
/*
Flags to set the work mode
*/
int local = 0, global = 0, export = 0;
int local = 0, global = 0, exportv = 0;
int erase = 0, list = 0, unexport=0;
int universal = 0, query=0;
@ -511,7 +511,7 @@ static int builtin_set( wchar_t **argv )
break;
case 'x':
export = 1;
exportv = 1;
break;
case 'l':
@ -556,7 +556,7 @@ static int builtin_set( wchar_t **argv )
also specify scope
*/
if( query && (erase || list || global || local || universal || export || unexport ) )
if( query && (erase || list || global || local || universal || exportv || unexport ) )
{
sb_printf(sb_err,
BUILTIN_ERR_COMBO,
@ -593,7 +593,7 @@ static int builtin_set( wchar_t **argv )
/*
Variables can only have one export status
*/
if( export && unexport )
if( exportv && unexport )
{
sb_printf( sb_err,
BUILTIN_ERR_EXPUNEXP,
@ -605,7 +605,7 @@ static int builtin_set( wchar_t **argv )
/*
Calculate the scope value for variable assignement
*/
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (export ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (exportv ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
if( query )
{

View file

@ -170,7 +170,7 @@ static void print_all( int hard )
getrlimit( resource_arr[i].resource, &ls );
l = hard ? ls.rlim_max:ls.rlim_cur;
wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
const wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
sb_printf( sb_out,
L"%-*ls %10ls-%lc) ",
@ -435,7 +435,7 @@ static int builtin_ulimit( wchar_t ** argv )
sb_append( sb_err,
argv[0],
L": Too many arguments\n",
(void *)0 );
NULL );
builtin_print_help( argv[0], sb_err );
return 1;
}
@ -506,7 +506,7 @@ static int builtin_ulimit( wchar_t ** argv )
sb_append( sb_err,
argv[0],
L": Too many arguments\n",
(void *)0 );
NULL );
builtin_print_help( argv[0], sb_err );
return 1;
}

View file

@ -43,6 +43,7 @@ parts of fish.
#include <time.h>
#include <sys/time.h>
#include <fcntl.h>
#include <algorithm>
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
@ -83,10 +84,10 @@ parts of fish.
#include "wildcard.h"
#include "parser.h"
#include "util.c"
#include "halloc.c"
#include "halloc_util.c"
#include "fallback.c"
#include "util.cpp"
#include "halloc.cpp"
#include "halloc_util.cpp"
#include "fallback.cpp"
/**
The number of milliseconds to wait between polls when attempting to acquire
@ -100,7 +101,7 @@ wchar_t ellipsis_char;
char *profile=0;
wchar_t *program_name;
const wchar_t *program_name;
int debug_level=1;
@ -138,7 +139,7 @@ void show_stackframe()
wchar_t **list_to_char_arr( array_list_t *l )
{
wchar_t ** res = malloc( sizeof(wchar_t *)*(al_get_count( l )+1) );
wchar_t ** res = (wchar_t **)malloc( sizeof(wchar_t *)*(al_get_count( l )+1) );
int i;
if( res == 0 )
{
@ -165,7 +166,7 @@ int fgetws2( wchar_t **b, int *len, FILE *f )
if( i+1 >= *len )
{
int new_len = maxi( 128, (*len)*2);
buff = realloc( buff, sizeof(wchar_t)*new_len );
buff = (wchar_t *)realloc( buff, sizeof(wchar_t)*new_len );
if( buff == 0 )
{
DIE_MEM();
@ -229,12 +230,22 @@ void sort_list( array_list_t *comp )
&str_cmp );
}
static bool string_sort_predicate(const wcstring& d1, const wcstring& d2)
{
return wcsfilecmp(d1.c_str(), d2.c_str()) < 0;
}
void sort_strings( std::vector<wcstring> &strings)
{
std::sort(strings.begin(), strings.end(), string_sort_predicate);
}
wchar_t *str2wcs( const char *in )
{
wchar_t *out;
size_t len = strlen(in);
out = malloc( sizeof(wchar_t)*(len+1) );
out = (wchar_t *)malloc( sizeof(wchar_t)*(len+1) );
if( !out )
{
@ -244,6 +255,14 @@ wchar_t *str2wcs( const char *in )
return str2wcs_internal( in, out );
}
wcstring str2wcstring( const char *in )
{
wchar_t *tmp = str2wcs(in);
wcstring result = tmp;
free(tmp);
return result;
}
wchar_t *str2wcs_internal( const char *in, wchar_t *out )
{
size_t res=0;
@ -310,7 +329,7 @@ char *wcs2str( const wchar_t *in )
{
char *out;
out = malloc( MAX_UTF8_BYTES*wcslen(in)+1 );
out = (char *)malloc( MAX_UTF8_BYTES*wcslen(in)+1 );
if( !out )
{
@ -320,6 +339,14 @@ char *wcs2str( const wchar_t *in )
return wcs2str_internal( in, out );
}
std::string wcs2string(const wcstring &input)
{
char *tmp = wcs2str(input.c_str());
std::string result = tmp;
free(tmp);
return result;
}
char *wcs2str_internal( const wchar_t *in, char *out )
{
size_t res=0;
@ -370,7 +397,7 @@ char **wcsv2strv( const wchar_t **in )
while( in[count] != 0 )
count++;
char **res = malloc( sizeof( char *)*(count+1));
char **res = (char **)malloc( sizeof( char *)*(count+1));
if( res == 0 )
{
DIE_MEM();
@ -400,7 +427,7 @@ wchar_t *wcsdupcat_internal( const wchar_t *a, ... )
}
va_end( va );
wchar_t *res = malloc( sizeof(wchar_t)*(len +1 ));
wchar_t *res = (wchar_t *)malloc( sizeof(wchar_t)*(len +1 ));
if( res == 0 )
{
DIE_MEM();
@ -426,7 +453,7 @@ wchar_t **strv2wcsv( const char **in )
while( in[count] != 0 )
count++;
wchar_t **res = malloc( sizeof( wchar_t *)*(count+1));
wchar_t **res = (wchar_t **)malloc( sizeof( wchar_t *)*(count+1));
if( res == 0 )
{
DIE_MEM();
@ -441,6 +468,19 @@ wchar_t **strv2wcsv( const char **in )
}
wcstring format_string(const wchar_t *format, ...)
{
va_list va;
va_start( va, format );
string_buffer_t buffer;
sb_init(&buffer);
sb_vprintf(&buffer, format, va);
wcstring result = (wchar_t *)buffer.buff;
sb_destroy(&buffer);
va_end( va );
return result;
}
wchar_t *wcsvarname( const wchar_t *str )
{
while( *str )
@ -526,8 +566,8 @@ const wchar_t *wsetlocale(int category, const wchar_t *locale)
/*
Use ellipsis if on known unicode system, otherwise use $
*/
char *ctype = setlocale( LC_CTYPE, (void *)0 );
ellipsis_char = (strstr( ctype, ".UTF")||strstr( ctype, ".utf") )?L'\u2026':L'$';
char *ctype = setlocale( LC_CTYPE, NULL );
ellipsis_char = (strstr( ctype, ".UTF")||strstr( ctype, ".utf") )?L'\x2026':L'$';
if( !res )
return 0;
@ -741,7 +781,7 @@ static wchar_t *escape_simple( const wchar_t *in )
{
wchar_t *out;
size_t len = wcslen(in);
out = malloc( sizeof(wchar_t)*(len+3));
out = (wchar_t *)malloc( sizeof(wchar_t)*(len+3));
if( !out )
DIE_MEM();
@ -752,7 +792,6 @@ static wchar_t *escape_simple( const wchar_t *in )
return out;
}
wchar_t *escape( const wchar_t *in_orig,
int flags )
{
@ -782,7 +821,7 @@ wchar_t *escape( const wchar_t *in_orig,
}
out = malloc( sizeof(wchar_t)*(wcslen(in)*4 + 1));
out = (wchar_t *)malloc( sizeof(wchar_t)*(wcslen(in)*4 + 1));
pos = out;
if( !out )
@ -931,6 +970,13 @@ wchar_t *escape( const wchar_t *in_orig,
return out;
}
wcstring escape_string( const wcstring &in, int escape_all ) {
wchar_t *tmp = escape(in.c_str(), escape_all);
wcstring result(tmp);
free(tmp);
return result;
}
wchar_t *unescape( const wchar_t * orig, int flags )
{
@ -1462,6 +1508,13 @@ wchar_t *unescape( const wchar_t * orig, int flags )
return in;
}
void unescape_string(wcstring &str, int escape_special)
{
wchar_t *result = unescape(str.c_str(), escape_special);
str.replace(str.begin(), str.end(), result);
free(result);
}
/**
Writes a pid_t in decimal representation to str.
str must contain sufficient space.
@ -1555,7 +1608,7 @@ static char *gen_unique_nfs_filename( const char *filename )
hnlen = sprint_rand_digits( hostname, HOST_NAME_MAX );
hostname[hnlen] = '\0';
}
newname = malloc( orglen + 1 /* period */ + hnlen + 1 /* period */ +
newname = (char *)malloc( orglen + 1 /* period */ + hnlen + 1 /* period */ +
/* max possible pid size: 0.31 ~= log(10)2 */
(int)(0.31 * sizeof(pid_t) * CHAR_BIT + 1)
+ 1 /* '\0' */ );
@ -1746,7 +1799,7 @@ void tokenize_variable_array( const wchar_t *val, array_list_t *out )
}
int create_directory( wchar_t *d )
int create_directory( const wchar_t *d )
{
int ok = 0;
struct stat buf;
@ -1769,16 +1822,14 @@ int create_directory( wchar_t *d )
{
if( errno == ENOENT )
{
wchar_t *dir = wcsdup( d );
dir = wdirname( dir );
if( !create_directory( dir ) )
wcstring dir = wdirname(d);
if( !create_directory( dir.c_str() ) )
{
if( !wmkdir( d, 0700 ) )
{
ok = 1;
}
}
free(dir);
}
}
@ -1857,3 +1908,37 @@ double timef()
return (double)tv.tv_sec + 0.000001*tv.tv_usec;
}
void append_path_component(wcstring &path, const wcstring &component)
{
size_t len = path.size();
if (len == 0)
{
path = component;
}
else
{
if (path[len-1] != L'/') path.push_back(L'/');
path.append(component);
}
}
extern "C" {
__attribute__((noinline)) void debug_thread_error(void) {}
}
void assert_is_main_thread(const char *who)
{
if (! pthread_main_np()) {
fprintf(stderr, "Warning: %s called off of main thread. Break on debug_thread_error to debug.\n", who);
debug_thread_error();
}
}
void assert_is_background_thread(const char *who)
{
if (pthread_main_np()) {
fprintf(stderr, "Warning: %s called on the main thread (may block!). Break on debug_thread_error to debug.\n", who);
debug_thread_error();
}
}

107
common.h
View file

@ -12,9 +12,16 @@
#include <stdio.h>
#include <wchar.h>
#include <termios.h>
#include <string>
#include <sstream>
#include <vector>
#include <errno.h>
#include "util.h"
/* Common string type */
typedef std::wstring wcstring;
/**
Maximum number of bytes used by a single utf-8 character
*/
@ -59,6 +66,10 @@
*/
#define ESCAPE_NO_QUOTED 2
/**
Helper macro for errors
*/
#define VOMIT_ON_FAILURE(a) do { if (0 != (a)) { int err = errno; fprintf(stderr, "%s failed on line %d in file %s: %d (%s)\n", #a, __LINE__, __FILE__, err, strerror(err)); abort(); }} while (0)
/**
Save the shell mode on startup so we can restore them on exit
@ -86,7 +97,7 @@ extern char *profile;
Name of the current program. Should be set at startup. Used by the
debug function.
*/
extern wchar_t *program_name;
extern const wchar_t *program_name;
/**
This macro is used to check that an input argument is not null. It
@ -148,7 +159,7 @@ extern wchar_t *program_name;
/**
Shorthand for wgettext call
*/
#define _(wstr) wgettext(wstr)
#define _(wstr) wgettext((const wchar_t *)wstr)
/**
Noop, used to tell xgettext that a string should be translated,
@ -159,11 +170,11 @@ extern wchar_t *program_name;
/**
Check if the specified stringelement is a part of the specified string list
*/
#define contains( str,... ) contains_internal( str, __VA_ARGS__, (void *)0 )
#define contains( str,... ) contains_internal( str, __VA_ARGS__, NULL )
/**
Concatenate all the specified strings into a single newly allocated one
*/
#define wcsdupcat( str,... ) wcsdupcat_internal( str, __VA_ARGS__, (void *)0 )
#define wcsdupcat( str,... ) wcsdupcat_internal( str, __VA_ARGS__, NULL )
/**
Print a stack trace to stderr
@ -196,6 +207,8 @@ int fgetws2( wchar_t **buff, int *len, FILE *f );
*/
void sort_list( array_list_t *comp );
void sort_strings( std::vector<wcstring> &strings);
/**
Returns a newly allocated wide character string equivalent of the
specified multibyte character string
@ -205,6 +218,15 @@ void sort_list( array_list_t *comp );
*/
wchar_t *str2wcs( const char *in );
/**
Returns a newly allocated wide character string equivalent of the
specified multibyte character string
This function encodes illegal character sequences in a reversible
way using the private use area.
*/
wcstring str2wcstring( const char *in );
/**
Converts the narrow character string \c in into it's wide
equivalent, stored in \c out. \c out must have enough space to fit
@ -223,6 +245,16 @@ wchar_t *str2wcs_internal( const char *in, wchar_t *out );
way using the private use area.
*/
char *wcs2str( const wchar_t *in );
std::string wcs2string(const wcstring &input);
void assert_is_main_thread(const char *who);
#define ASSERT_IS_MAIN_THREAD_TRAMPOLINE(x) assert_is_main_thread(x)
#define ASSERT_IS_MAIN_THREAD() ASSERT_IS_MAIN_THREAD_TRAMPOLINE(__FUNCTION__)
void assert_is_background_thread(const char *who);
#define ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(x) assert_is_background_thread(x)
#define ASSERT_IS_BACKGROUND_THREAD() ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(__FUNCTION__)
/**
Converts the wide character string \c in into it's narrow
@ -234,6 +266,67 @@ char *wcs2str( const wchar_t *in );
*/
char *wcs2str_internal( const wchar_t *in, char *out );
/**
Converts some type to a wstring.
*/
template<typename T>
wcstring format_val(T x) {
std::wstringstream stream;
stream << x;
return stream.str();
}
template<typename T>
T from_string(const wcstring &x) {
T result;
std::wstringstream stream(x);
stream >> result;
return result;
}
class scoped_lock {
pthread_mutex_t *lock;
public:
scoped_lock(pthread_mutex_t &mutex) : lock(&mutex) {
VOMIT_ON_FAILURE(pthread_mutex_lock(lock));
}
~scoped_lock() {
VOMIT_ON_FAILURE(pthread_mutex_unlock(lock));
}
};
class wcstokenizer {
wchar_t *buffer, *str, *state;
const wcstring sep;
public:
wcstokenizer(const wcstring &s, const wcstring &separator) : sep(separator) {
wchar_t *wcsdup(const wchar_t *s);
buffer = wcsdup(s.c_str());
str = buffer;
state = NULL;
}
bool next(wcstring &result) {
wchar_t *tmp = wcstok(str, sep.c_str(), &state);
str = NULL;
if (tmp) result = tmp;
return tmp != NULL;
}
~wcstokenizer() {
free(buffer);
}
};
/**
Appends a path component, with a / if necessary
*/
void append_path_component(wcstring &path, const wcstring &component);
wcstring format_string(const wchar_t *format, ...);
/**
Returns a newly allocated wide character string array equivalent of
the specified multibyte character string array
@ -368,6 +461,7 @@ void debug( int level, const wchar_t *msg, ... );
*/
wchar_t *escape( const wchar_t *in, int escape_all );
wcstring escape_string( const wcstring &in, int escape_all );
/**
Expand backslashed escapes and substitute them with their unescaped
@ -383,6 +477,9 @@ wchar_t *escape( const wchar_t *in, int escape_all );
wchar_t *unescape( const wchar_t * in,
int escape_special );
void unescape_string( wcstring &str,
int escape_special );
/**
Attempt to acquire a lock based on a lockfile, waiting LOCKPOLLINTERVAL
milliseconds between polls and timing out after timeout seconds,
@ -440,7 +537,7 @@ void tokenize_variable_array( const wchar_t *val, array_list_t *out );
\return 0 if, at the time of function return the directory exists, -1 otherwise.
*/
int create_directory( wchar_t *d );
int create_directory( const wchar_t *d );
/**
Print a short message about how to file a bug report to stderr

View file

@ -192,7 +192,7 @@ void completion_allocate( array_list_t *context,
const wchar_t *desc,
int flags )
{
completion_t *res = halloc( context, sizeof( completion_t) );
completion_t *res = (completion_t *)halloc( context, sizeof( completion_t) );
res->completion = halloc_wcsdup( context, comp );
if( desc )
res->description = halloc_wcsdup( context, desc );
@ -276,7 +276,7 @@ static int condition_test( const wchar_t *condition )
if( !condition_cache )
{
condition_cache = malloc( sizeof( hash_table_t ) );
condition_cache = (hash_table_t *)malloc( sizeof( hash_table_t ) );
if( !condition_cache )
{
DIE_MEM();
@ -302,7 +302,7 @@ static int condition_test( const wchar_t *condition )
*/
}
if( wcscmp( test_res, CC_TRUE ) == 0 )
if( wcscmp( (const wchar_t *)test_res, CC_TRUE ) == 0 )
{
return 1;
}
@ -365,7 +365,7 @@ static complete_entry_t *complete_get_exact_entry( const wchar_t *cmd,
if( c == 0 )
{
if( !(c = malloc( sizeof(complete_entry_t) )))
if( !(c = (complete_entry_t *)malloc( sizeof(complete_entry_t) )))
{
DIE_MEM();
}
@ -415,7 +415,7 @@ void complete_add( const wchar_t *cmd,
c = complete_get_exact_entry( cmd, cmd_type );
opt = halloc( 0, sizeof( complete_entry_opt_t ) );
opt = (complete_entry_opt_t *)halloc( 0, sizeof( complete_entry_opt_t ) );
opt->next = c->first_option;
c->first_option = opt;
@ -423,7 +423,7 @@ void complete_add( const wchar_t *cmd,
{
int len = 1 + ((result_mode & NO_COMMON) != 0);
c->short_opt_str =
realloc( c->short_opt_str,
(wchar_t *)realloc( c->short_opt_str,
sizeof(wchar_t)*(wcslen( c->short_opt_str ) + 1 + len) );
wcsncat( c->short_opt_str,
&short_opt, 1 );
@ -664,7 +664,7 @@ int complete_is_valid_option( const wchar_t *str,
context = halloc( 0, 0 );
if( !(short_validated = halloc( context, wcslen( opt ) )))
if( !(short_validated = (char *)halloc( context, wcslen( opt ) )))
{
DIE_MEM();
}
@ -1513,7 +1513,7 @@ static int complete_param( const wchar_t *cmd_orig,
int match=0, match_no_case=0;
string_buffer_t *whole_opt = sb_halloc( context );
sb_append( whole_opt, o->old_mode?L"-":L"--", o->long_opt, (void *)0 );
sb_append( whole_opt, o->old_mode?L"-":L"--", o->long_opt, NULL );
match = wcsncmp( str, (wchar_t *)whole_opt->buff, wcslen(str) )==0;

299
env.cpp
View file

@ -12,7 +12,10 @@
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include <pwd.h>
#include <set>
#include <map>
#if HAVE_NCURSES_H
#include <ncurses.h>
@ -97,7 +100,7 @@ typedef struct env_node
/**
Does this node contain any variables which are exported to subshells
*/
int export;
int exportv;
/**
Pointer to next level
@ -113,7 +116,7 @@ typedef struct env_node
*/
typedef struct var_entry
{
int export; /**< Whether the variable should be exported */
int exportv; /**< Whether the variable should be exported */
size_t size; /**< The maximum length (excluding the NULL) that will fit into this var_entry_t */
#if __STDC_VERSION__ < 199901L
@ -124,6 +127,13 @@ typedef struct var_entry
}
var_entry_t;
class variable_entry_t {
bool exportv; /**< Whether the variable should be exported */
wcstring value; /**< Value of the variable */
};
static pthread_mutex_t env_lock = PTHREAD_MUTEX_INITIALIZER;
/**
Top node on the function stack
*/
@ -143,12 +153,23 @@ static hash_table_t *global;
/**
Table of variables that may not be set using the set command.
*/
static hash_table_t env_read_only;
static std::set<wcstring> env_read_only;
static bool is_read_only(const wcstring &key)
{
return env_read_only.find(key) != env_read_only.end();
}
/**
Table of variables whose value is dynamically calculated, such as umask, status, etc
*/
static hash_table_t env_electric;
static std::set<wcstring> env_electric;
static bool is_electric(const wcstring &key)
{
return env_electric.find(key) != env_electric.end();
}
/**
Exported variable array used by execv
@ -197,7 +218,7 @@ static const wchar_t *locale_variable[] =
L"LC_MONETARY",
L"LC_NUMERIC",
L"LC_TIME",
(void *)0
NULL
}
;
@ -207,7 +228,7 @@ static const wchar_t *locale_variable[] =
static void clear_hash_entry( void *key, void *data )
{
var_entry_t *entry = (var_entry_t *)data;
if( entry->export )
if( entry->exportv )
{
has_changed = 1;
}
@ -282,7 +303,7 @@ static void handle_locale()
const wchar_t *lc_all = env_get( L"LC_ALL" );
const wchar_t *lang;
int i;
wchar_t *old = wcsdup(wsetlocale( LC_MESSAGES, (void *)0 ));
wchar_t *old = wcsdup(wsetlocale( LC_MESSAGES, NULL ));
/*
Array of locale constants corresponding to the local variable names defined in locale_variable
@ -323,7 +344,7 @@ static void handle_locale()
}
}
if( wcscmp( wsetlocale( LC_MESSAGES, (void *)0 ), old ) != 0 )
if( wcscmp( wsetlocale( LC_MESSAGES, NULL ), old ) != 0 )
{
/*
@ -357,7 +378,7 @@ static void universal_callback( int type,
const wchar_t *name,
const wchar_t *val )
{
wchar_t *str=0;
const wchar_t *str=0;
if( is_locale( name ) )
{
@ -533,26 +554,22 @@ void env_init()
b_init( &export_buffer );
/*
These variables can not be altered directly by the user
env_read_only variables can not be altered directly by the user
*/
hash_init( &env_read_only, &hash_wcs_func, &hash_wcs_cmp );
hash_put( &env_read_only, L"status", L"" );
hash_put( &env_read_only, L"history", L"" );
hash_put( &env_read_only, L"version", L"" );
hash_put( &env_read_only, L"_", L"" );
hash_put( &env_read_only, L"LINES", L"" );
hash_put( &env_read_only, L"COLUMNS", L"" );
hash_put( &env_read_only, L"PWD", L"" );
hash_put( &env_read_only, L"SHLVL", L"" );
/*
Names of all dynamically calculated variables
*/
hash_init( &env_electric, &hash_wcs_func, &hash_wcs_cmp );
hash_put( &env_electric, L"history", L"" );
hash_put( &env_electric, L"status", L"" );
hash_put( &env_electric, L"umask", L"" );
const wchar_t * const ro_keys[] = {
L"status",
L"history",
L"version",
L"_",
L"LINES",
L"COLUMNS",
L"PWD",
L"SHLVL",
};
for (size_t i=0; i < sizeof ro_keys / sizeof *ro_keys; i++) {
env_read_only.insert(ro_keys[i]);
}
/*
HOME and USER should be writeable by root, since this can be a
@ -560,14 +577,21 @@ void env_init()
*/
if( getuid() != 0 )
{
hash_put( &env_read_only, L"HOME", L"" );
hash_put( &env_read_only, L"USER", L"" );
env_read_only.insert(L"HOME");
env_read_only.insert(L"USER");
}
top = malloc( sizeof(env_node_t) );
/*
Names of all dynamically calculated variables
*/
env_electric.insert(L"history");
env_electric.insert(L"status");
env_electric.insert(L"umask");
top = (env_node_t *)malloc( sizeof(env_node_t) );
top->next = 0;
top->new_scope = 0;
top->export=0;
top->exportv=0;
hash_init( &top->env, &hash_wcs_func, &hash_wcs_cmp );
global_env = top;
global = &top->env;
@ -656,8 +680,8 @@ void env_init()
/* add an extra space for digit dump (9+1=10) */
size_t i = wcslen( shlvl ) + 2 * sizeof(wchar_t);
nshlvl = malloc(i);
end_nshlvl = calloc( 1, sizeof(nshlvl) );
nshlvl = (wchar_t *)malloc(i);
end_nshlvl = (wchar_t **)calloc( 1, sizeof(nshlvl) );
if ( !nshlvl || !end_nshlvl )
DIE_MEM();
@ -697,9 +721,9 @@ void env_destroy()
env_pop();
}
hash_destroy( &env_read_only );
env_read_only.clear();
env_electric.clear();
hash_destroy( &env_electric );
hash_foreach( global, &clear_hash_entry );
hash_destroy( global );
@ -771,8 +795,7 @@ int env_set( const wchar_t *key,
halloc_free( context );
}
if( (var_mode & ENV_USER ) &&
hash_get( &env_read_only, key ) )
if( (var_mode & ENV_USER ) && is_read_only(key) )
{
return ENV_PERM;
}
@ -813,7 +836,7 @@ int env_set( const wchar_t *key,
if( var_mode & ENV_UNIVERSAL )
{
int export = 0;
int exportv = 0;
if( !(var_mode & ENV_EXPORT ) &&
!(var_mode & ENV_UNEXPORT ) )
@ -822,10 +845,10 @@ int env_set( const wchar_t *key,
}
else
{
export = (var_mode & ENV_EXPORT );
exportv = (var_mode & ENV_EXPORT );
}
env_universal_set( key, val, export );
env_universal_set( key, val, exportv );
is_universal = 1;
}
@ -838,7 +861,7 @@ int env_set( const wchar_t *key,
e = (var_entry_t *) hash_get( &node->env,
key );
if( e->export )
if( e->exportv )
{
has_changed_new = 1;
}
@ -856,7 +879,7 @@ int env_set( const wchar_t *key,
if( !(var_mode & ENV_EXPORT ) &&
!(var_mode & ENV_UNEXPORT ) )
{
var_mode = e->export?ENV_EXPORT:0;
var_mode = e->exportv?ENV_EXPORT:0;
}
}
else
@ -869,7 +892,7 @@ int env_set( const wchar_t *key,
if( env_universal_get( key ) )
{
int export = 0;
int exportv = 0;
if( !(var_mode & ENV_EXPORT ) &&
!(var_mode & ENV_UNEXPORT ) )
@ -878,10 +901,10 @@ int env_set( const wchar_t *key,
}
else
{
export = (var_mode & ENV_EXPORT );
exportv = (var_mode & ENV_EXPORT );
}
env_universal_set( key, val, export );
env_universal_set( key, val, exportv );
is_universal = 1;
done = 1;
@ -925,9 +948,9 @@ int env_set( const wchar_t *key,
{
entry = old_entry;
if( !!(var_mode & ENV_EXPORT) || entry->export )
if( !!(var_mode & ENV_EXPORT) || entry->exportv )
{
entry->export = !!(var_mode & ENV_EXPORT);
entry->exportv = !!(var_mode & ENV_EXPORT);
has_changed_new = 1;
}
}
@ -935,7 +958,7 @@ int env_set( const wchar_t *key,
{
free( v );
entry = malloc( sizeof( var_entry_t ) +
entry = (var_entry_t *)malloc( sizeof( var_entry_t ) +
sizeof(wchar_t )*(val_len+1));
if( !entry )
@ -947,12 +970,12 @@ int env_set( const wchar_t *key,
if( var_mode & ENV_EXPORT)
{
entry->export = 1;
entry->exportv = 1;
has_changed_new = 1;
}
else
{
entry->export = 0;
entry->exportv = 0;
}
}
@ -961,9 +984,9 @@ int env_set( const wchar_t *key,
hash_put( &node->env, k, entry );
if( entry->export )
if( entry->exportv )
{
node->export=1;
node->exportv=1;
}
if( free_val )
@ -1031,7 +1054,7 @@ static int try_remove( env_node_t *n,
if( old_key != 0 )
{
var_entry_t * v = (var_entry_t *)old_val;
if( v->export )
if( v->exportv )
{
has_changed = 1;
}
@ -1064,8 +1087,7 @@ int env_remove( const wchar_t *key, int var_mode )
CHECK( key, 1 );
if( (var_mode & ENV_USER ) &&
hash_get( &env_read_only, key ) )
if( (var_mode & ENV_USER ) && is_read_only(key) )
{
return 2;
}
@ -1115,9 +1137,119 @@ int env_remove( const wchar_t *key, int var_mode )
return !erased;
}
wcstring env_get_string( const wchar_t *key )
{
scoped_lock lock(env_lock);
CHECK( key, 0 );
if( wcscmp( key, L"history" ) == 0 )
{
wcstring result;
wchar_t *current;
int i;
int add_current=0;
current = reader_get_buffer();
if( current && wcslen( current ) )
{
add_current=1;
result += current;
}
for( i=add_current;; i++ )
{
// PCA This looks bad!
wchar_t *next = history_get( i-add_current );
if( !next )
{
break;
}
if( i!=0)
{
result += ARRAY_SEP_STR;
}
result += next;
}
return result;
}
else if( wcscmp( key, L"COLUMNS" )==0 )
{
return format_val((long)common_get_width());
}
else if( wcscmp( key, L"LINES" )==0 )
{
return format_val((long)common_get_width());
}
else if( wcscmp( key, L"status" )==0 )
{
return format_val((long)proc_get_last_status());
}
else if( wcscmp( key, L"umask" )==0 )
{
return format_string(L"0%0.3o", get_umask() );
}
else {
var_entry_t *res;
env_node_t *env = top;
wchar_t *item;
wcstring result;
while( env != 0 )
{
res = (var_entry_t *) hash_get( &env->env,
key );
if( res != 0 )
{
if( wcscmp( res->val, ENV_NULL )==0)
{
return 0;
}
else
{
return res->val;
}
}
if( env->new_scope )
{
env = global_env;
}
else
{
env = env->next;
}
}
if( !proc_had_barrier)
{
proc_had_barrier=1;
env_universal_barrier();
}
item = env_universal_get( key );
if( !item || (wcscmp( item, ENV_NULL )==0))
{
return 0;
}
else
{
return item;
}
}
}
wchar_t *env_get( const wchar_t *key )
{
ASSERT_IS_MAIN_THREAD();
if (! pthread_main_np())
{
fwprintf(stderr, L"env_get(%ls)\n", key);
}
var_entry_t *res;
env_node_t *env = top;
wchar_t *item;
@ -1238,7 +1370,7 @@ int env_exist( const wchar_t *key, int mode )
*/
if( ! (mode & ENV_LOCAL) && ! (mode & ENV_UNIVERSAL) )
{
if( hash_get( &env_read_only, key ) || hash_get( &env_electric, key ) )
if( is_read_only(key) || is_electric(key) )
{
return 1;
}
@ -1297,7 +1429,7 @@ static int local_scope_exports( env_node_t *n )
if( n==global_env )
return 0;
if( n->export )
if( n->exportv )
return 1;
if( n->new_scope )
@ -1308,9 +1440,9 @@ static int local_scope_exports( env_node_t *n )
void env_push( int new_scope )
{
env_node_t *node = malloc( sizeof(env_node_t) );
env_node_t *node = (env_node_t *)malloc( sizeof(env_node_t) );
node->next = top;
node->export=0;
node->exportv=0;
hash_init( &node->env, &hash_wcs_func, &hash_wcs_cmp );
node->new_scope=new_scope;
if( new_scope )
@ -1342,7 +1474,7 @@ void env_pop()
if( killme->new_scope )
{
has_changed |= killme->export || local_scope_exports( killme->next );
has_changed |= killme->exportv || local_scope_exports( killme->next );
}
top = top->next;
@ -1372,8 +1504,8 @@ static void add_key_to_hash( void *key,
void *aux )
{
var_entry_t *e = (var_entry_t *)data;
if( ( e->export && get_names_show_exported) ||
( !e->export && get_names_show_unexported) )
if( ( e->exportv && get_names_show_exported) ||
( !e->exportv && get_names_show_unexported) )
{
hash_put( (hash_table_t *)aux, key, 0 );
}
@ -1389,17 +1521,6 @@ static void add_to_hash( void *k, void *aux )
0 );
}
/**
Add key to list
*/
static void add_key_to_list( void * key,
void * val,
void *aux )
{
al_push( (array_list_t *)aux, key );
}
void env_get_names( array_list_t *l, int flags )
{
int show_local = flags & ENV_LOCAL;
@ -1448,8 +1569,11 @@ void env_get_names( array_list_t *l, int flags )
add_key_to_hash,
&names );
if( get_names_show_unexported )
hash_foreach2( &env_electric, &add_key_to_list, l );
if( get_names_show_unexported ) {
for (std::set<wcstring>::iterator iter = env_electric.begin(); iter != env_electric.end(); iter++) {
al_push( l, iter->c_str() );
}
}
if( get_names_show_exported )
{
@ -1486,7 +1610,7 @@ static void export_func1( void *k, void *v, void *aux )
hash_remove( h, k, 0, 0 );
if( val_entry->export && wcscmp( val_entry->val, ENV_NULL ) )
if( val_entry->exportv && wcscmp( val_entry->val, ENV_NULL ) )
{
hash_put( h, k, val_entry->val );
}
@ -1588,7 +1712,7 @@ char **env_export_arr( int recalc )
hash_foreach2( &vals, &export_func2, &export_buffer );
hash_destroy( &vals );
export_arr = realloc( export_arr,
export_arr = (char **)realloc( export_arr,
sizeof(char *)*(hash_get_count( &vals) + 1) );
for( i=0; i<export_buffer.used; i++ )
@ -1606,3 +1730,24 @@ char **env_export_arr( int recalc )
}
return export_arr;
}
env_vars::env_vars(const wchar_t * const *keys)
{
ASSERT_IS_MAIN_THREAD();
for (size_t i=0; keys[i]; i++) {
const wchar_t *val = env_get(keys[i]);
if (val) {
vars[keys[i]] = val;
}
}
}
env_vars::env_vars() { }
const wchar_t *env_vars::get(const wchar_t *key) const
{
std::map<wcstring, wcstring>::const_iterator iter = vars.find(key);
return (iter == vars.end() ? NULL : iter->second.c_str());
}
const wchar_t * const env_vars::highlighting_keys[] = {L"PATH", L"CDPATH", L"HIGHLIGHT_DELAY", NULL};

20
env.h
View file

@ -6,8 +6,10 @@
#define FISH_ENV_H
#include <wchar.h>
#include <map>
#include "util.h"
#include "common.h"
/**
Flag for local (to the current block) variable
@ -93,6 +95,11 @@ int env_set( const wchar_t *key,
*/
wchar_t *env_get( const wchar_t *key );
/**
Gets the variable with the specified name, or an empty string if it does not exist.
*/
wcstring env_get_string( const wchar_t *key );
/**
Returns 1 if the specified key exists. This can't be reliably done
using env_get, since env_get returns null for 0-element arrays
@ -138,5 +145,18 @@ void env_get_names( array_list_t *l, int flags );
*/
int env_set_pwd();
class env_vars {
std::map<wcstring, wcstring> vars;
public:
env_vars(const wchar_t * const * keys);
env_vars(void);
const wchar_t *get(const wchar_t *key) const;
// vars necessary for highlighting
static const wchar_t * const highlighting_keys[];
};
#endif

View file

@ -113,7 +113,7 @@ static int get_socket( int fork_ok )
uname = strdup( pw->pw_name );
}
name = malloc( strlen(dir) +
name = (char *)malloc( strlen(dir) +
strlen(uname) +
strlen(SOCK_FILENAME) +
2 );
@ -405,7 +405,7 @@ void env_universal_barrier()
}
void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
void env_universal_set( const wchar_t *name, const wchar_t *value, int exportv )
{
message_t *msg;
@ -418,11 +418,11 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
if( is_dead() )
{
env_universal_common_set( name, value, export );
env_universal_common_set( name, value, exportv );
}
else
{
msg = create_message( export?SET_EXPORT:SET,
msg = create_message( exportv?SET_EXPORT:SET,
name,
value);

View file

@ -17,7 +17,10 @@ extern connection_t env_universal_server;
/**
Initialize the envuni library
*/
void env_universal_init();
void env_universal_init( wchar_t * p,
wchar_t *u,
void (*sf)(),
void (*cb)( int type, const wchar_t *name, const wchar_t *val ));
/**
Free memory used by envuni
*/
@ -37,7 +40,7 @@ int env_universal_get_export( const wchar_t *name );
/**
Set the value of a universal variable
*/
void env_universal_set( const wchar_t *name, const wchar_t *val, int export );
void env_universal_set( const wchar_t *name, const wchar_t *val, int exportv );
/**
Erase a universal variable

View file

@ -92,7 +92,7 @@
*/
typedef struct var_uni_entry
{
int export; /**< Whether the variable should be exported */
int exportv; /**< Whether the variable should be exported */
wchar_t val[1]; /**< The value of the variable */
}
var_uni_entry_t;
@ -221,7 +221,7 @@ static wchar_t *utf2wcs( const char *in )
size_t nconv;
char *nout;
out = malloc( out_len );
out = (wchar_t *)malloc( out_len );
nout = (char *)out;
if( !out )
@ -331,7 +331,7 @@ static char *wcs2utf( const wchar_t *in )
size_t nconv;
char *nout;
out = malloc( out_len );
out = (char *)malloc( out_len );
nout = (char *)out;
in_len *= sizeof( wchar_t );
@ -557,7 +557,7 @@ static int match( const wchar_t *msg, const wchar_t *cmd )
return 1;
}
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int export )
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int exportv )
{
var_uni_entry_t *entry;
wchar_t *name;
@ -565,13 +565,13 @@ void env_universal_common_set( const wchar_t *key, const wchar_t *val, int expor
CHECK( key, );
CHECK( val, );
entry = malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
entry = (var_uni_entry_t *)malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
name = wcsdup(key);
if( !entry || !name )
DIE_MEM();
entry->export=export;
entry->exportv=exportv;
wcscpy( entry->val, val );
env_universal_common_remove( name );
@ -580,7 +580,7 @@ void env_universal_common_set( const wchar_t *key, const wchar_t *val, int expor
if( callback )
{
callback( export?SET_EXPORT:SET, name, val );
callback( exportv?SET_EXPORT:SET, name, val );
}
}
@ -599,9 +599,9 @@ static void parse_message( wchar_t *msg,
if( match( msg, SET_STR ) || match( msg, SET_EXPORT_STR ))
{
wchar_t *name, *tmp;
int export = match( msg, SET_EXPORT_STR );
int exportv = match( msg, SET_EXPORT_STR );
name = msg+(export?wcslen(SET_EXPORT_STR):wcslen(SET_STR));
name = msg+(exportv?wcslen(SET_EXPORT_STR):wcslen(SET_STR));
while( wcschr( L"\t ", *name ) )
name++;
@ -611,14 +611,14 @@ static void parse_message( wchar_t *msg,
wchar_t *key;
wchar_t *val;
key = malloc( sizeof( wchar_t)*(tmp-name+1));
key = (wchar_t *)malloc( sizeof( wchar_t)*(tmp-name+1));
memcpy( key, name, sizeof( wchar_t)*(tmp-name));
key[tmp-name]=0;
val = tmp+1;
val = unescape( val, 0 );
env_universal_common_set( key, val, export );
env_universal_common_set( key, val, exportv );
free( val );
free( key );
@ -826,7 +826,7 @@ message_t *create_message( int type,
free(esc);
sz = strlen(type==SET?SET_MBS:SET_EXPORT_MBS) + strlen(key) + strlen(val) + 4;
msg = malloc( sizeof( message_t ) + sz );
msg = (message_t *)malloc( sizeof( message_t ) + sz );
if( !msg )
DIE_MEM();
@ -846,7 +846,7 @@ message_t *create_message( int type,
case ERASE:
{
sz = strlen(ERASE_MBS) + strlen(key) + 3;
msg = malloc( sizeof( message_t ) + sz );
msg = (message_t *)malloc( sizeof( message_t ) + sz );
if( !msg )
DIE_MEM();
@ -859,7 +859,7 @@ message_t *create_message( int type,
case BARRIER:
{
msg = malloc( sizeof( message_t ) +
msg = (message_t *)malloc( sizeof( message_t ) +
strlen( BARRIER_MBS ) +2);
if( !msg )
DIE_MEM();
@ -869,7 +869,7 @@ message_t *create_message( int type,
case BARRIER_REPLY:
{
msg = malloc( sizeof( message_t ) +
msg = (message_t *)malloc( sizeof( message_t ) +
strlen( BARRIER_REPLY_MBS ) +2);
if( !msg )
DIE_MEM();
@ -902,8 +902,8 @@ static void add_key_to_hash( void *key,
void *aux )
{
var_uni_entry_t *e = (var_uni_entry_t *)data;
if( ( e->export && get_names_show_exported) ||
( !e->export && get_names_show_unexported) )
if( ( e->exportv && get_names_show_exported) ||
( !e->exportv && get_names_show_unexported) )
al_push( (array_list_t *)aux, key );
}
@ -931,7 +931,7 @@ int env_universal_common_get_export( const wchar_t *name )
{
var_uni_entry_t *e = (var_uni_entry_t *)hash_get( &env_universal_var, name );
if( e )
return e->export;
return e->exportv;
return 0;
}
@ -953,7 +953,7 @@ static void enqueue( void *k,
const var_uni_entry_t *val = (const var_uni_entry_t *)v;
dyn_queue_t *queue = (dyn_queue_t *)q;
message_t *msg = create_message( val->export?SET_EXPORT:SET, key, val->val );
message_t *msg = create_message( val->exportv?SET_EXPORT:SET, key, val->val );
msg->count=1;
q_put( queue, msg );

View file

@ -160,7 +160,7 @@ void env_universal_common_get_names( array_list_t *l,
Do not call this function. Create a message to do it. This function
is only to be used when fishd is dead.
*/
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int export );
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int exportv );
/**
Remove the specified variable.

View file

@ -84,45 +84,45 @@ static array_list_t *blocked;
they must name the same function.
*/
static int event_match( event_t *class, event_t *instance )
static int event_match( event_t *classv, event_t *instance )
{
if( class->function_name && instance->function_name )
if( classv->function_name && instance->function_name )
{
if( wcscmp( class->function_name, instance->function_name ) != 0 )
if( wcscmp( classv->function_name, instance->function_name ) != 0 )
return 0;
}
if( class->type == EVENT_ANY )
if( classv->type == EVENT_ANY )
return 1;
if( class->type != instance->type )
if( classv->type != instance->type )
return 0;
switch( class->type )
switch( classv->type )
{
case EVENT_SIGNAL:
if( class->param1.signal == EVENT_ANY_SIGNAL )
if( classv->param1.signal == EVENT_ANY_SIGNAL )
return 1;
return class->param1.signal == instance->param1.signal;
return classv->param1.signal == instance->param1.signal;
case EVENT_VARIABLE:
return wcscmp( instance->param1.variable,
class->param1.variable )==0;
classv->param1.variable )==0;
case EVENT_EXIT:
if( class->param1.pid == EVENT_ANY_PID )
if( classv->param1.pid == EVENT_ANY_PID )
return 1;
return class->param1.pid == instance->param1.pid;
return classv->param1.pid == instance->param1.pid;
case EVENT_JOB_ID:
return class->param1.job_id == instance->param1.job_id;
return classv->param1.job_id == instance->param1.job_id;
case EVENT_GENERIC:
return wcscmp( instance->param1.param,
class->param1.param )==0;
classv->param1.param )==0;
}
@ -139,7 +139,7 @@ static int event_match( event_t *class, event_t *instance )
*/
static event_t *event_copy( event_t *event, int copy_arguments )
{
event_t *e = malloc( sizeof( event_t ) );
event_t *e = (event_t *)malloc( sizeof( event_t ) );
if( !e )
DIE_MEM();

View file

@ -164,7 +164,7 @@ const wchar_t *event_get_desc( event_t *e );
/**
Fire a generic event with the specified name
*/
#define event_fire_generic( ... ) event_fire_generic_internal( __VA_ARGS__, (void *)0 )
#define event_fire_generic( ... ) event_fire_generic_internal( __VA_ARGS__, NULL )
void event_fire_generic_internal(const wchar_t *name,...);

View file

@ -23,6 +23,7 @@
#include <assert.h>
#include <dirent.h>
#include <time.h>
#include <vector>
#ifdef HAVE_SIGINFO_H
#include <siginfo.h>
@ -541,7 +542,7 @@ static void launch_process( process_t *p )
while( p->argv[count] != 0 )
count++;
res = malloc( sizeof(wchar_t*)*(count+2));
res = (wchar_t **)malloc( sizeof(wchar_t*)*(count+2));
res[0] = L"/bin/sh";
res[1] = p->actual_cmd;
@ -712,7 +713,7 @@ static io_data_t *io_transmogrify( io_data_t * in )
if( !in )
return 0;
out = malloc( sizeof( io_data_t ) );
out = (io_data_t *)malloc( sizeof( io_data_t ) );
if( !out )
DIE_MEM();
@ -1001,7 +1002,7 @@ void exec( job_t *j )
Input redirection - create a new gobetween process to take
care of buffering
*/
process_t *fake = halloc( j, sizeof(process_t) );
process_t *fake = (process_t *)halloc( j, sizeof(process_t) );
fake->type = INTERNAL_BUFFER;
fake->pipe_write_fd = 1;
j->first_process->pipe_read_fd = input_redirect->fd;
@ -1193,7 +1194,7 @@ void exec( job_t *j )
if( orig_def )
{
def = halloc_register( j, wcsdup(orig_def) );
def = (wchar_t *)halloc_register( j, wcsdup(orig_def) );
}
if( def == 0 )
{
@ -1204,7 +1205,7 @@ void exec( job_t *j )
parser_push_block( shadows?FUNCTION_CALL:FUNCTION_CALL_NO_SHADOW );
current_block->param2.function_call_process = p;
current_block->param1.function_call_name = halloc_register( current_block, wcsdup( p->argv[0] ) );
current_block->param1.function_call_name = (wchar_t *)halloc_register( current_block, wcsdup( p->argv[0] ) );
/*
@ -1711,6 +1712,21 @@ void exec( job_t *j )
}
int exec_subshell2( const wcstring &cmd, std::vector<wcstring> &outputs )
{
array_list_t lst;
al_init(&lst);
int result = exec_subshell(cmd.c_str(), &lst);
int i, max = al_get_count(&lst);
for (i=0; i < max; i++) {
wchar_t *tmp = (wchar_t *)al_get(&lst, i);
outputs.push_back(tmp);
free(tmp);
}
al_destroy(&lst);
return result;
}
int exec_subshell( const wchar_t *cmd,
array_list_t *lst )
{

4
exec.h
View file

@ -9,9 +9,11 @@
#define FISH_EXEC_H
#include <wchar.h>
#include <vector>
#include "proc.h"
#include "util.h"
#include "common.h"
/**
pipe redirection error message
@ -54,6 +56,8 @@ void exec( job_t *j );
__warn_unused int exec_subshell( const wchar_t *cmd,
array_list_t *l );
__warn_unused int exec_subshell2( const wcstring &cmd, std::vector<wcstring> &outputs );
/**
Loops over close until thesyscall was run without beeing

View file

@ -23,6 +23,7 @@ parameter expansion.
#include <signal.h>
#include <assert.h>
#include <vector>
#ifdef SunOS
#include <procfs.h>
@ -117,6 +118,35 @@ parameter expansion.
*/
#define UNCLEAN L"$*?\\\"'({})"
/* An adapter class for calling functions that expect a wchar_t * and array_list_t */
class wcstring_adapter
{
private:
std::vector<wcstring> *outputs;
public:
wchar_t *str;
array_list_t lst;
wcstring_adapter(const wcstring &in, std::vector<wcstring> &outs)
{
outputs = &outs;
str = wcsdup(in.c_str());
al_init(&lst);
}
~wcstring_adapter()
{
int i, max = al_get_count(&lst);
for (i=0; i < max; i++) {
wchar_t *tmp = (wchar_t *)al_get(&lst, i);
outputs->push_back(tmp);
free(tmp);
}
al_destroy(&lst);
//str is free'd by the function we called
}
};
int expand_is_clean( const wchar_t *in )
{
@ -206,7 +236,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
L"'",
el,
L"'",
(void *)0 );
NULL );
}
else
{
@ -232,7 +262,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
L"'",
el,
L"'",
(void *)0 );
NULL );
}
else
{
@ -405,7 +435,7 @@ static int find_process( const wchar_t *proc,
{
{
result = malloc(sizeof(wchar_t)*16 );
result = (wchar_t *)malloc(sizeof(wchar_t)*16 );
swprintf( result, 16, L"%d", j->pgid );
al_push( out, result );
found = 1;
@ -435,7 +465,7 @@ static int find_process( const wchar_t *proc,
}
else
{
result = malloc(sizeof(wchar_t)*16 );
result = (wchar_t *)malloc(sizeof(wchar_t)*16 );
swprintf( result, 16, L"%d", j->pgid );
al_push( out, result );
found = 1;
@ -471,7 +501,7 @@ static int find_process( const wchar_t *proc,
}
else
{
result = malloc(sizeof(wchar_t)*16 );
result = (wchar_t *)malloc(sizeof(wchar_t)*16 );
swprintf( result, 16, L"%d", p->pid );
al_push( out, result );
found = 1;
@ -493,13 +523,14 @@ static int find_process( const wchar_t *proc,
return 1;
}
pdir_name = malloc( sizeof(wchar_t)*256 );
pfile_name = malloc( sizeof(wchar_t)*64 );
pdir_name = (wchar_t *)malloc( sizeof(wchar_t)*256 );
pfile_name = (wchar_t *)malloc( sizeof(wchar_t)*64 );
wcscpy( pdir_name, L"/proc/" );
while( (next=wreaddir(dir))!=0 )
wcstring nameStr;
while (wreaddir(dir, nameStr))
{
wchar_t *name = next->d_name;
const wchar_t *name = nameStr.c_str();
struct stat buf;
if( !iswnumeric( name ) )
@ -643,7 +674,7 @@ static int expand_pid( wchar_t *in,
{
if( wcscmp( (in+1), SELF_STR )==0 )
{
wchar_t *str= malloc( sizeof(wchar_t)*32);
wchar_t *str= (wchar_t *)malloc( sizeof(wchar_t)*32);
free(in);
swprintf( str, 32, L"%d", getpid() );
al_push( out, str );
@ -656,7 +687,7 @@ static int expand_pid( wchar_t *in,
if( proc_last_bg_pid > 0 )
{
str = malloc( sizeof(wchar_t)*32);
str = (wchar_t *)malloc( sizeof(wchar_t)*32);
free(in);
swprintf( str, 32, L"%d", proc_last_bg_pid );
al_push( out, str );
@ -688,6 +719,12 @@ static int expand_pid( wchar_t *in,
return 1;
}
static int expand_pid2( const wcstring &in, int flags, std::vector<wcstring> &outputs )
{
wcstring_adapter adapter(in, outputs);
return expand_pid(adapter.str, flags, &adapter.lst);
}
void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
{
@ -767,7 +804,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
/**
Parse an array slicing specification
*/
static int parse_slice( wchar_t *in, wchar_t **end_ptr, array_list_t *idx )
static int parse_slice( const wchar_t *in, wchar_t **end_ptr, array_list_t *idx )
{
@ -807,13 +844,60 @@ static int parse_slice( wchar_t *in, wchar_t **end_ptr, array_list_t *idx )
{
// debug( 0, L"Remainder is '%ls', slice def was %d characters long", in+pos, pos );
*end_ptr = in+pos;
*end_ptr = (wchar_t *)(in+pos);
}
// debug( 0, L"ok, done" );
return 0;
}
static int parse_slice2( const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx )
{
wchar_t *end;
int pos = 1;
// debug( 0, L"parse_slice on '%ls'", in );
while( 1 )
{
long tmp;
while( iswspace(in[pos]) || (in[pos]==INTERNAL_SEPARATOR))
pos++;
if( in[pos] == L']' )
{
pos++;
break;
}
errno=0;
tmp = wcstol( &in[pos], &end, 10 );
if( ( errno ) || ( end == &in[pos] ) )
{
return 1;
}
// debug( 0, L"Push idx %d", tmp );
idx.push_back(tmp);
pos = end-in;
}
if( end_ptr )
{
// debug( 0, L"Remainder is '%ls', slice def was %d characters long", in+pos, pos );
*end_ptr = (wchar_t *)(in+pos);
}
// debug( 0, L"ok, done" );
return 0;
}
/**
@ -961,7 +1045,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
else
{
/* Replace each index in var_idx_list inplace with the string value at the specified index */
al_set( var_idx_list, j, wcsdup(al_get( &var_item_list, tmp-1 ) ) );
al_set( var_idx_list, j, wcsdup((const wchar_t *)al_get( &var_item_list, tmp-1 ) ) );
}
}
/* Free strings in list var_item_list and truncate it */
@ -1016,7 +1100,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
new_len = wcslen(in) - (stop_pos-start_pos+1);
new_len += wcslen( next) +2;
if( !(new_in = malloc( sizeof(wchar_t)*new_len )))
if( !(new_in = (wchar_t *)malloc( sizeof(wchar_t)*new_len )))
{
DIE_MEM();
}
@ -1099,6 +1183,12 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
return is_ok;
}
static int expand_variables2( const wcstring &in, std::vector<wcstring> &outputs, int last_idx )
{
wcstring_adapter adapter(in, outputs);
return expand_variables(adapter.str, &adapter.lst, last_idx);
}
/**
Perform bracket expansion
*/
@ -1207,7 +1297,7 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
wchar_t *whole_item;
int item_len = pos-item_begin;
whole_item = malloc( sizeof(wchar_t)*(tot_len + item_len + 1) );
whole_item = (wchar_t *)malloc( sizeof(wchar_t)*(tot_len + item_len + 1) );
wcslcpy( whole_item, in, len1+1 );
wcslcpy( whole_item+len1, item_begin, item_len+1 );
wcscpy( whole_item+len1+item_len, bracket_end+1 );
@ -1234,6 +1324,12 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
return 1;
}
static int expand_brackets2( const wcstring &in, int flags, std::vector<wcstring> outputs )
{
wcstring_adapter adapter(in, outputs);
return expand_brackets(adapter.str, flags, &adapter.lst);
}
/**
Perform cmdsubst expansion
*/
@ -1279,7 +1375,7 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
item_begin = paran_begin+1;
sub_res = al_halloc( context );
if( !(subcmd = halloc( context, sizeof(wchar_t)*(paran_end-paran_begin) )))
if( !(subcmd = (wchar_t *)halloc( context, sizeof(wchar_t)*(paran_end-paran_begin) )))
{
halloc_free( context );
return 0;
@ -1384,6 +1480,138 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
return 1;
}
/**
Perform cmdsubst expansion
*/
static int expand_cmdsubst2( const wcstring &input, std::vector<wcstring> &outList )
{
wchar_t *paran_begin=0, *paran_end=0;
int len1;
wchar_t prev=0;
std::vector<wcstring> sub_res;
size_t i, j;
const wchar_t *item_begin;
wchar_t *tail_begin = 0;
const wchar_t * const in = input.c_str();
switch( parse_util_locate_cmdsubst(in,
&paran_begin,
&paran_end,
0 ) )
{
case -1:
error( SYNTAX_ERROR,
-1,
L"Mismatched parans" );
return 0;
case 0:
outList.push_back(input);
return 1;
case 1:
break;
}
len1 = (paran_begin-in);
prev=0;
item_begin = paran_begin+1;
const wcstring subcmd(paran_begin + 1, paran_end-paran_begin - 1);
if( exec_subshell2( subcmd, sub_res) == -1 )
{
error( CMDSUBST_ERROR, -1, L"Unknown error while evaulating command substitution" );
return 0;
}
tail_begin = paran_end + 1;
if( *tail_begin == L'[' )
{
std::vector<long> slice_idx;
wchar_t *slice_end;
if( parse_slice2( tail_begin, &slice_end, slice_idx ) )
{
error( SYNTAX_ERROR, -1, L"Invalid index value" );
return 0;
}
else
{
std::vector<wcstring> sub_res2;
tail_begin = slice_end;
for( i=0; i < slice_idx.size(); i++ )
{
long idx = slice_idx.at(i);
if( idx < 0 )
{
idx = sub_res.size() + idx + 1;
}
if( idx < 1 || (size_t)idx > sub_res.size() )
{
error( SYNTAX_ERROR, -1, L"Invalid index value" );
return 0;
}
idx = idx-1;
sub_res2.push_back(sub_res.at(idx));
// debug( 0, L"Pushing item '%ls' with index %d onto sliced result", al_get( sub_res, idx ), idx );
//sub_res[idx] = 0; // ??
}
sub_res = sub_res2;
}
}
/*
Recursively call ourselves to expand any remaining command
substitutions. The result of this recursive call using the tail
of the string is inserted into the tail_expand array list
*/
std::vector<wcstring> tail_expand;
expand_cmdsubst2( tail_begin, tail_expand );
/*
Combine the result of the current command substitution with the
result of the recursive tail expansion
*/
for( i=0; i<sub_res.size(); i++ )
{
wcstring sub_item = sub_res.at(i);
wcstring sub_item2 = escape_string(sub_item, 1);
for( j=0; j < tail_expand.size(); j++ )
{
wcstring whole_item;
wcstring tail_item = tail_expand.at(j);
//sb_append_substring( &whole_item, in, len1 );
whole_item.append(in, len1);
//sb_append_char( &whole_item, INTERNAL_SEPARATOR );
whole_item.push_back(INTERNAL_SEPARATOR);
//sb_append_substring( &whole_item, sub_item2, item_len );
whole_item.append(sub_item2);
//sb_append_char( &whole_item, INTERNAL_SEPARATOR );
whole_item.push_back(INTERNAL_SEPARATOR);
//sb_append( &whole_item, tail_item );
whole_item.append(tail_item);
//al_push( out, whole_item.buff );
outList.push_back(whole_item);
}
}
return 1;
}
/**
Wrapper around unescape funtion. Issues an error() on failiure.
*/
@ -1395,99 +1623,93 @@ static wchar_t *expand_unescape( const wchar_t * in, int escape_special )
return res;
}
/**
Attempts tilde expansion. Of the string specified. If tilde
expansion is performed, the original string is freed and a new
string allocated using malloc is returned, otherwise, the original
string is returned.
*/
static wchar_t * expand_tilde_internal( wchar_t *in )
static wcstring expand_unescape_string( const wcstring &in, int escape_special )
{
wcstring tmp = in;
unescape_string(tmp, escape_special);
/* Need to detect error here */
return tmp;
}
CHECK( in, 0 );
/**
Attempts tilde expansion of the string specified, modifying it in place.
*/
static void expand_tilde_internal( wcstring &input )
{
const wchar_t * const in = input.c_str();
if( in[0] == HOME_DIRECTORY )
{
int tilde_error = 0;
wchar_t *home=0;
wchar_t *new_in=0;
wchar_t *old_in=0;
size_t tail_idx;
wcstring home;
if( in[1] == '/' || in[1] == '\0' )
{
/* Current users home directory */
home = env_get( L"HOME" );
if( home )
home = wcsdup(home);
else
home = wcsdup(L"");
if( !home )
{
*in = L'~';
tilde_error = 1;
}
old_in = &in[1];
home = env_get_string( L"HOME" );
tail_idx = 1;
}
else
{
/* Some other users home directory */
wchar_t *name;
wchar_t *name_end = wcschr( in, L'/' );
if( name_end == 0 )
const wchar_t *name_end = wcschr( in, L'/' );
if (name_end)
{
name_end = in+wcslen( in );
tail_idx = name_end - in;
}
name = wcsndup( in+1, name_end-in-1 );
old_in = name_end;
char *name_str = wcs2str( name );
else
{
tail_idx = wcslen( in );
}
tail_idx = name_end - in;
wcstring name_str = input.substr(1, name_end-in-1);
const char *name_cstr = wcs2str( name_str.c_str() );
struct passwd *userinfo =
getpwnam( name_str );
getpwnam( name_cstr );
free((void *)name_cstr);
if( userinfo == 0 )
{
tilde_error = 1;
*in = L'~';
}
else
{
home = str2wcs(userinfo->pw_dir);
if( !home )
{
*in = L'~';
tilde_error = 1;
home = str2wcstring(userinfo->pw_dir);
}
}
free( name_str );
free(name);
}
if( !tilde_error && home && old_in )
if (! tilde_error)
{
new_in = wcsdupcat( home, old_in );
input.replace(input.begin(), input.begin() + tail_idx, home);
}
free(home);
free( in );
return new_in;
}
return in;
}
wchar_t *expand_tilde( wchar_t *in)
static wchar_t * expand_tilde_internal_compat( wchar_t *in )
{
CHECK( in, 0 );
wcstring tmp = in;
expand_tilde_internal(tmp);
free(in);
return wcsdup(tmp.c_str());
}
if( in[0] == L'~' )
void expand_tilde( wcstring &input)
{
if( input[0] == L'~' )
{
in[0] = HOME_DIRECTORY;
return expand_tilde_internal( in );
input[0] = HOME_DIRECTORY;
expand_tilde_internal( input );
}
return in;
}
wchar_t * expand_tilde_compat( wchar_t *input )
{
if (input[0] == L'~') {
input[0] = HOME_DIRECTORY;
return expand_tilde_internal_compat(input);
}
return input;
}
/**
@ -1531,6 +1753,231 @@ static void remove_internal_separator( const void *s, int conv )
*out=0;
}
static void remove_internal_separator2( wcstring &s, int conv )
{
wchar_t *tmp = wcsdup(s.c_str());
remove_internal_separator(tmp, conv);
s = tmp;
free(tmp);
}
int expand_string2( const wcstring &input, std::vector<wcstring> &output, int flags )
{
std::vector<wcstring> list1, list2;
std::vector<wcstring> *in, *out;
size_t i;
int cmdsubst_ok = 1;
int res = EXPAND_OK;
int start_count = output.size();
if( (!(flags & ACCEPT_INCOMPLETE)) && expand_is_clean( input.c_str() ) )
{
output.push_back(input);
return EXPAND_OK;
}
if( EXPAND_SKIP_CMDSUBST & flags )
{
wchar_t *begin, *end;
if( parse_util_locate_cmdsubst( input.c_str(),
&begin,
&end,
1 ) != 0 )
{
error( CMDSUBST_ERROR, -1, L"Command substitutions not allowed" );
return EXPAND_ERROR;
}
list1.push_back(input);
}
else
{
cmdsubst_ok = expand_cmdsubst2(input, list1);
}
if( !cmdsubst_ok )
{
return EXPAND_ERROR;
}
else
{
in = &list1;
out = &list2;
for( i=0; i < in->size(); i++ )
{
/*
We accept incomplete strings here, since complete uses
expand_string to expand incomplete strings from the
commandline.
*/
int unescape_flags = UNESCAPE_SPECIAL | UNESCAPE_INCOMPLETE;
wcstring next = expand_unescape_string( in->at(i), unescape_flags );
if( EXPAND_SKIP_VARIABLES & flags )
{
for (size_t i=0; i < next.size(); i++) {
if (next.at(i) == VARIABLE_EXPAND) {
next[i] = L'$';
}
}
out->push_back(next);
}
else
{
if(!expand_variables2( next, *out, next.size() - 1 ))
{
return EXPAND_ERROR;
}
}
}
in->clear();
in = &list2;
out = &list1;
for( i=0; i < in->size(); i++ )
{
wcstring next = in->at(i);
if( !expand_brackets2( next, flags, *out ))
{
return EXPAND_ERROR;
}
}
in->clear();
in = &list1;
out = &list2;
for( i=0; i < in->size(); i++ )
{
wcstring next = in->at(i);
expand_tilde_internal(next);
if( flags & ACCEPT_INCOMPLETE )
{
if( next[0] == PROCESS_EXPAND )
{
/*
If process expansion matches, we are not
interested in other completions, so we
short-circut and return
*/
expand_pid2( next, flags, output );
return EXPAND_OK;
}
else
{
out->push_back(next);
}
}
else
{
if( !expand_pid2( next, flags, *out ) )
{
return EXPAND_ERROR;
}
}
}
in->clear();
in = &list2;
out = &list1;
for( i=0; i < in->size(); i++ )
{
wcstring next_str = in->at(i);
int wc_res;
remove_internal_separator2( next_str, EXPAND_SKIP_WILDCARDS & flags );
const wchar_t *next = next_str.c_str();
if( ((flags & ACCEPT_INCOMPLETE) && (!(flags & EXPAND_SKIP_WILDCARDS))) ||
wildcard_has( next, 1 ) )
{
const wchar_t *start, *rest;
std::vector<wcstring> *list = out;
if( next[0] == '/' )
{
start = L"/";
rest = &next[1];
}
else
{
start = L"";
rest = next;
}
if( flags & ACCEPT_INCOMPLETE )
{
list = &output;
}
wc_res = wildcard_expand_string(rest, start, flags, *list);
if( !(flags & ACCEPT_INCOMPLETE) )
{
switch( wc_res )
{
case 0:
{
if( !(flags & ACCEPT_INCOMPLETE) )
{
if( res == EXPAND_OK )
res = EXPAND_WILDCARD_NO_MATCH;
break;
}
}
case 1:
{
size_t j;
res = EXPAND_WILDCARD_MATCH;
sort_strings( *out );
for( j=0; j< out->size(); j++ )
{
wcstring next = out->at(j);
output.push_back(next);
}
out->clear();
break;
}
case -1:
{
return EXPAND_ERROR;
}
}
}
}
else
{
if( flags & ACCEPT_INCOMPLETE)
{
}
else
{
output.push_back(next);
}
}
}
}
return res;
}
/**
The real expansion function. expand_one is just a wrapper around this one.
@ -1670,7 +2117,7 @@ int expand_string( void *context,
continue;
}
if( !(next=expand_tilde_internal( next ) ) )
if( !(next=expand_tilde_internal_compat( next ) ) )
{
al_destroy( in );
al_destroy( out );

View file

@ -18,6 +18,8 @@
#include <wchar.h>
#include "util.h"
#include "common.h"
#include <list>
/**
Flag specifying that cmdsubst expansion should be skipped
@ -144,6 +146,7 @@ enum
\return One of EXPAND_OK, EXPAND_ERROR, EXPAND_WILDCARD_MATCH and EXPAND_WILDCARD_NO_MATCH. EXPAND_WILDCARD_NO_MATCH and EXPAND_WILDCARD_MATCH are normal exit conditions used only on strings containing wildcards to tell if the wildcard produced any matches.
*/
__warn_unused int expand_string( void *context, wchar_t *in, array_list_t *out, int flag );
__warn_unused int expand_string2( const wcstring &input, std::list<wcstring> &output, int flag );
/**
expand_one is identical to expand_string, except it will fail if in
@ -168,14 +171,12 @@ wchar_t *expand_one( void *context, wchar_t *in, int flag );
wchar_t *expand_escape_variable( const wchar_t *in );
/**
Perform tilde expansion and nothing else on the specified string.
Perform tilde expansion and nothing else on the specified string, which is modified in place.
If tilde expansion is needed, the original string is freed and a
new string, allocated using malloc, is returned.
\param in the string to tilde expand
\param input the string to tilde expand
*/
wchar_t *expand_tilde(wchar_t *in);
void expand_tilde(wcstring &input);
wchar_t * expand_tilde_compat( wchar_t *input );
/**

View file

@ -807,7 +807,7 @@ wchar_t *wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **save_ptr)
wchar_t *wcsdup( const wchar_t *in )
{
size_t len=wcslen(in);
wchar_t *out = malloc( sizeof( wchar_t)*(len+1));
wchar_t *out = (wchar_t *)malloc( sizeof( wchar_t)*(len+1));
if( out == 0 )
{
return 0;
@ -886,7 +886,7 @@ int wcwidth( wchar_t c )
#ifndef HAVE_WCSNDUP
wchar_t *wcsndup( const wchar_t *in, int c )
{
wchar_t *res = malloc( sizeof(wchar_t)*(c+1) );
wchar_t *res = (wchar_t *)malloc( sizeof(wchar_t)*(c+1) );
if( res == 0 )
{
return 0;

View file

@ -174,7 +174,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
} else if ( last[0] != '1' || last[1] ) {
sb_append( out, last, L">" );
}
sb_append( out, L"| " );
sb_append( out, L" | " );
is_command = 1;
break;
}
@ -187,7 +187,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
} else {
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
sb_append( out, L">" );
sb_append( out, L"> " );
}
break;
}
@ -200,7 +200,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
} else {
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
sb_append( out, L">>" );
sb_append( out, L">> " );
}
break;
}
@ -210,7 +210,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
sb_append( out, L" " );
if ( wcscmp( last, L"0" ) != 0 )
sb_append( out, last );
sb_append( out, L"<" );
sb_append( out, L"< " );
break;
}
@ -219,7 +219,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
sb_append( out, L" " );
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
sb_append( out, L">&" );
sb_append( out, L">& " );
break;
}

View file

@ -951,7 +951,7 @@ static void mangle_completions( array_list_t *l, const wchar_t *prefix )
{
wchar_t *next = (wchar_t *)al_get( l, i );
wchar_t *start, *end;
comp_t *comp = halloc( global_context, sizeof( comp_t ) );
comp_t *comp = (comp_t *)halloc( global_context, sizeof( comp_t ) );
comp->comp = al_halloc( global_context );
for( start=end=next; 1; end++ )
@ -1075,7 +1075,7 @@ static void init( int mangle_descriptors, int out )
env_universal_init( 0, 0, 0, 0);
input_common_init( &interrupt_handler );
output_set_writer( &pager_buffered_writer );
pager_buffer = halloc( global_context, sizeof( buffer_t ) );
pager_buffer = (buffer_t *)halloc( global_context, sizeof( buffer_t ) );
halloc_register_function( global_context, (void (*)(void *))&b_destroy, pager_buffer );
sigemptyset( & act.sa_mask );

View file

@ -80,7 +80,7 @@ static int err_count=0;
/**
Print formatted output
*/
static void say( wchar_t *blah, ... )
static void say( const wchar_t *blah, ... )
{
va_list va;
va_start( va, blah );
@ -92,7 +92,7 @@ static void say( wchar_t *blah, ... )
/**
Print formatted error string
*/
static void err( wchar_t *blah, ... )
static void err( const wchar_t *blah, ... )
{
va_list va;
va_start( va, blah );
@ -109,7 +109,7 @@ static void err( wchar_t *blah, ... )
*/
static int pq_compare( void *e1, void *e2 )
{
return e1-e2;
return (intptr_t)e1-(intptr_t)e2;
}
/**
@ -120,7 +120,7 @@ static void pq_test( int elements )
int i;
int prev;
int *count = calloc( sizeof(int), 100 );
int *count = (int *)calloc( sizeof(int), 100 );
priority_queue_t q;
pq_init( &q, pq_compare );
@ -236,7 +236,7 @@ static int hash_test( long elements )
for( i=1; i< elements+1; i++ )
{
hash_put( &h, (void*)i, (void*)100l-i );
hash_put( &h, (void*)i, (void*)(100l-i) );
}
for( i=1; i< elements+1; i++ )
@ -536,12 +536,12 @@ static void test_convert()
if( !o || !w || !n )
{
err( L"Conversion cycle of string %s produced null pointer on %s", o, w?L"str2wcs":L"wcs2str" );
err( L"Line %d - Conversion cycle of string %s produced null pointer on %s", __LINE__, o, w?L"str2wcs":L"wcs2str" );
}
if( strcmp(o, n) )
{
err( L"%d: Conversion cycle of string %s produced different string %s", i, o, n );
err( L"Line %d - %d: Conversion cycle of string %s produced different string %s", __LINE__, i, o, n );
}
free( w );
free( n );
@ -588,13 +588,13 @@ static void test_tok()
{
wchar_t *str = L"string <redirection 2>&1 'nested \"quoted\" '(string containing subshells ){and,brackets}$as[$well (as variable arrays)]";
const wchar_t *str = L"string <redirection 2>&1 'nested \"quoted\" '(string containing subshells ){and,brackets}$as[$well (as variable arrays)]";
const int types[] =
{
TOK_STRING, TOK_REDIRECT_IN, TOK_STRING, TOK_REDIRECT_FD, TOK_STRING, TOK_STRING, TOK_END
}
;
int i;
size_t i;
say( L"Test correct tokenization" );
@ -711,7 +711,7 @@ static int expand_test( const wchar_t *in, int flags, ... )
break;
}
if( wcscmp( al_get( &out, i ),arg) != 0 )
if( wcscmp( (wchar_t *)al_get( &out, i ),arg) != 0 )
{
res=0;
break;

View file

@ -162,7 +162,7 @@ static char *get_socket_filename()
uname = strdup( pw->pw_name );
}
name = malloc( strlen(dir)+ strlen(uname)+ strlen(SOCK_FILENAME) + 2 );
name = (char *)malloc( strlen(dir)+ strlen(uname)+ strlen(SOCK_FILENAME) + 2 );
if( name == NULL )
{
wperror( L"get_socket_filename" );
@ -200,7 +200,7 @@ static void handle_term( int signal )
static char *acquire_socket_lock( const char *sock_name )
{
int len = strlen( sock_name );
char *lockfile = malloc( len + strlen( LOCKPOSTFIX ) + 1 );
char *lockfile = (char *)malloc( len + strlen( LOCKPOSTFIX ) + 1 );
if( lockfile == NULL )
{
@ -491,7 +491,7 @@ static void load_or_save( int save)
gethostname( hostname, HOSTNAME_LEN );
name = malloc( strlen(dir)+ strlen(FILE)+ strlen(hostname) + 2 );
name = (char *)malloc( strlen(dir)+ strlen(FILE)+ strlen(hostname) + 2 );
strcpy( name, dir );
strcat( name, "/" );
strcat( name, FILE );
@ -692,12 +692,12 @@ int main( int argc, char ** argv )
}
else
{
connection_t *new = malloc( sizeof(connection_t));
connection_init( new, child_socket );
new->next = conn;
send( new->fd, GREETING, strlen(GREETING), MSG_DONTWAIT );
enqueue_all( new );
conn=new;
connection_t *newc = (connection_t *)malloc( sizeof(connection_t));
connection_init( newc, child_socket );
newc->next = conn;
send( newc->fd, GREETING, strlen(GREETING), MSG_DONTWAIT );
enqueue_all( newc );
conn=newc;
}
}
}

View file

@ -11,10 +11,13 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <unistd.h>
#include <termios.h>
#include <signal.h>
#include <pthread.h>
#include <errno.h>
#include "wutil.h"
#include "fallback.h"
@ -75,7 +78,37 @@ typedef struct
/**
Table containing all functions
*/
static hash_table_t function;
static hash_table_t functions;
/* Lock for functions */
static pthread_mutex_t functions_lock;
/* Helper macro for vomiting */
#define VOMIT_ON_FAILURE(a) do { if (0 != (a)) { int err = errno; fprintf(stderr, "%s failed on line %d in file %s: %d (%s)\n", #a, __LINE__, __FILE__, err, strerror(err)); abort(); }} while (0)
static int kLockDepth = 0;
static char kLockFunction[1024];
/**
Lock and unlock the functions hash
*/
static void lock_functions(const char *func) {
VOMIT_ON_FAILURE(pthread_mutex_lock(&functions_lock));
if (! kLockDepth++) {
strcat(kLockFunction, func);
}
}
static void unlock_functions(void) {
if (! --kLockDepth) {
memset(kLockFunction, 0, sizeof kLockFunction);
}
VOMIT_ON_FAILURE(pthread_mutex_unlock(&functions_lock));
}
#define LOCK_FUNCTIONS() lock_functions(__FUNCTION__)
#define UNLOCK_FUNCTIONS() unlock_functions()
/**
Kludgy flag set by the load function in order to tell function_add
@ -93,9 +126,13 @@ static int load( const wchar_t *name )
int was_autoload = is_autoload;
int res;
function_internal_data_t *data;
data = (function_internal_data_t *)hash_get( &function, name );
if( data && !data->is_autoload )
LOCK_FUNCTIONS();
data = (function_internal_data_t *)hash_get( &functions, name );
if( data && !data->is_autoload ) {
UNLOCK_FUNCTIONS();
return 0;
}
UNLOCK_FUNCTIONS();
is_autoload = 1;
res = parse_util_load( name,
@ -130,10 +167,10 @@ static void autoload_names( array_list_t *out, int get_hidden )
if( !dir )
continue;
struct wdirent *next;
while( (next=wreaddir(dir))!=0 )
wcstring name;
while (wreaddir(dir, name))
{
wchar_t *fn = next->d_name;
const wchar_t *fn = name.c_str();
wchar_t *suffix;
if( !get_hidden && fn[0] == L'_' )
continue;
@ -157,9 +194,15 @@ static void autoload_names( array_list_t *out, int get_hidden )
void function_init()
{
hash_init( &function,
hash_init( &functions,
&hash_wcs_func,
&hash_wcs_cmp );
pthread_mutexattr_t a;
VOMIT_ON_FAILURE(pthread_mutexattr_init(&a));
VOMIT_ON_FAILURE(pthread_mutexattr_settype(&a,PTHREAD_MUTEX_RECURSIVE));
VOMIT_ON_FAILURE(pthread_mutex_init(&functions_lock, &a));
VOMIT_ON_FAILURE(pthread_mutexattr_destroy(&a));
}
/**
@ -172,8 +215,10 @@ static void clear_entry( void *key, void *value )
void function_destroy()
{
hash_foreach( &function, &clear_entry );
hash_destroy( &function );
LOCK_FUNCTIONS();
hash_foreach( &functions, &clear_entry );
hash_destroy( &functions );
UNLOCK_FUNCTIONS();
}
@ -185,10 +230,10 @@ void function_add( function_data_t *data )
CHECK( data->name, );
CHECK( data->definition, );
LOCK_FUNCTIONS();
function_remove( data->name );
d = halloc( 0, sizeof( function_internal_data_t ) );
d = (function_internal_data_t *)halloc( 0, sizeof( function_internal_data_t ) );
d->definition_offset = parse_util_lineno( parser_get_buffer(), current_block->tok_pos )-1;
d->definition = halloc_wcsdup( d, data->definition );
@ -209,13 +254,154 @@ void function_add( function_data_t *data )
d->is_autoload = is_autoload;
d->shadows = data->shadows;
hash_put( &function, intern(data->name), d );
hash_put( &functions, intern(data->name), d );
for( i=0; i<al_get_count( data->events ); i++ )
{
event_add_handler( (event_t *)al_get( data->events, i ) );
}
UNLOCK_FUNCTIONS();
}
static int function_exists_internal( const wchar_t *cmd, int autoload )
{
int res;
CHECK( cmd, 0 );
if( parser_keywords_is_reserved(cmd) )
return 0;
LOCK_FUNCTIONS();
if ( autoload ) load( cmd );
res = (hash_get(&functions, cmd) != 0 );
UNLOCK_FUNCTIONS();
return res;
}
int function_exists( const wchar_t *cmd )
{
return function_exists_internal( cmd, 1 );
}
int function_exists_no_autoload( const wchar_t *cmd )
{
return function_exists_internal( cmd, 0 );
}
void function_remove( const wchar_t *name )
{
void *key;
void *dv;
function_internal_data_t *d;
event_t ev;
CHECK( name, );
LOCK_FUNCTIONS();
hash_remove( &functions,
name,
&key,
&dv );
d=(function_internal_data_t *)dv;
if( !key ) {
UNLOCK_FUNCTIONS();
return;
}
ev.type=EVENT_ANY;
ev.function_name=name;
event_remove( &ev );
halloc_free( d );
/*
Notify the autoloader that the specified function is erased, but
only if this call to fish_remove is not made by the autoloader
itself.
*/
if( !is_autoload )
{
parse_util_unload( name, L"fish_function_path", 0 );
}
UNLOCK_FUNCTIONS();
}
const wchar_t *function_get_definition( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
LOCK_FUNCTIONS();
load( name );
data = (function_internal_data_t *)hash_get( &functions, name );
UNLOCK_FUNCTIONS();
if( data == 0 )
return 0;
return data->definition;
}
array_list_t *function_get_named_arguments( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
LOCK_FUNCTIONS();
load( name );
data = (function_internal_data_t *)hash_get( &functions, name );
UNLOCK_FUNCTIONS();
if( data == 0 )
return 0;
return data->named_arguments;
}
int function_get_shadows( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
LOCK_FUNCTIONS();
load( name );
data = (function_internal_data_t *)hash_get( &functions, name );
UNLOCK_FUNCTIONS();
if( data == 0 )
return 0;
return data->shadows;
}
const wchar_t *function_get_desc( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
load( name );
LOCK_FUNCTIONS();
data = (function_internal_data_t *)hash_get( &functions, name );
UNLOCK_FUNCTIONS();
if( data == 0 )
return 0;
return _(data->description);
}
void function_set_desc( const wchar_t *name, const wchar_t *desc )
{
function_internal_data_t *data;
CHECK( name, );
CHECK( desc, );
load( name );
LOCK_FUNCTIONS();
data = (function_internal_data_t *)hash_get( &functions, name );
UNLOCK_FUNCTIONS();
if( data == 0 )
return;
data->description = halloc_wcsdup( data, desc );
}
int function_copy( const wchar_t *name, const wchar_t *new_name )
@ -226,11 +412,11 @@ int function_copy( const wchar_t *name, const wchar_t *new_name )
CHECK( name, 0 );
CHECK( new_name, 0 );
orig_d = (function_internal_data_t *)hash_get(&function, name);
orig_d = (function_internal_data_t *)hash_get(&functions, name);
if( !orig_d )
return 0;
d = halloc(0, sizeof( function_internal_data_t ) );
d = (function_internal_data_t *)halloc(0, sizeof( function_internal_data_t ) );
d->definition_offset = orig_d->definition_offset;
d->definition = halloc_wcsdup( d, orig_d->definition );
if( orig_d->named_arguments )
@ -249,129 +435,11 @@ int function_copy( const wchar_t *name, const wchar_t *new_name )
d->is_autoload = 0;
}
hash_put( &function, intern(new_name), d );
hash_put( &functions, intern(new_name), d );
return 1;
}
int function_exists( const wchar_t *cmd )
{
CHECK( cmd, 0 );
if( parser_keywords_is_reserved(cmd) )
return 0;
load( cmd );
return (hash_get(&function, cmd) != 0 );
}
void function_remove( const wchar_t *name )
{
void *key;
void *dv;
function_internal_data_t *d;
event_t ev;
CHECK( name, );
hash_remove( &function,
name,
&key,
&dv );
d=(function_internal_data_t *)dv;
if( !key )
return;
ev.type=EVENT_ANY;
ev.function_name=name;
event_remove( &ev );
halloc_free( d );
/*
Notify the autoloader that the specified function is erased, but
only if this call to fish_remove is not made by the autoloader
itself.
*/
if( !is_autoload )
{
parse_util_unload( name, L"fish_function_path", 0 );
}
}
const wchar_t *function_get_definition( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return 0;
return data->definition;
}
array_list_t *function_get_named_arguments( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return 0;
return data->named_arguments;
}
int function_get_shadows( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return 0;
return data->shadows;
}
const wchar_t *function_get_desc( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return 0;
return _(data->description);
}
void function_set_desc( const wchar_t *name, const wchar_t *desc )
{
function_internal_data_t *data;
CHECK( name, );
CHECK( desc, );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return;
data->description = halloc_wcsdup( data, desc );
}
/**
Search arraylist of strings for specified string
*/
@ -384,7 +452,7 @@ static int al_contains_str( array_list_t *list, const wchar_t * str )
for( i=0; i<al_get_count( list ); i++ )
{
if( wcscmp( al_get( list, i ), str) == 0 )
if( wcscmp( (const wchar_t *)al_get( list, i ), str) == 0 )
{
return 1;
}
@ -424,17 +492,18 @@ static void get_names_internal_all( void *key,
void function_get_names( array_list_t *list, int get_hidden )
{
CHECK( list, );
LOCK_FUNCTIONS();
autoload_names( list, get_hidden );
if( get_hidden )
{
hash_foreach2( &function, &get_names_internal_all, list );
hash_foreach2( &functions, &get_names_internal_all, list );
}
else
{
hash_foreach2( &function, &get_names_internal, list );
hash_foreach2( &functions, &get_names_internal, list );
}
UNLOCK_FUNCTIONS();
}
@ -443,8 +512,9 @@ const wchar_t *function_get_definition_file( const wchar_t *name )
function_internal_data_t *data;
CHECK( name, 0 );
data = (function_internal_data_t *)hash_get( &function, name );
LOCK_FUNCTIONS();
data = (function_internal_data_t *)hash_get( &functions, name );
UNLOCK_FUNCTIONS();
if( data == 0 )
return 0;
@ -457,8 +527,9 @@ int function_get_definition_offset( const wchar_t *name )
function_internal_data_t *data;
CHECK( name, -1 );
data = (function_internal_data_t *)hash_get( &function, name );
LOCK_FUNCTIONS();
data = (function_internal_data_t *)hash_get( &functions, name );
UNLOCK_FUNCTIONS();
if( data == 0 )
return -1;

View file

@ -93,6 +93,11 @@ void function_set_desc( const wchar_t *name, const wchar_t *desc );
*/
int function_exists( const wchar_t *name );
/**
Returns true if the function with the name name exists, without triggering autoload.
*/
int function_exists_no_autoload( const wchar_t *name );
/**
Insert all function names into l. These are not copies of the
strings and should not be freed after use.
@ -126,15 +131,16 @@ int function_get_definition_offset( const wchar_t *name );
*/
array_list_t *function_get_named_arguments( const wchar_t *name );
/**
Returns whether this function shadows variables of the underlying function
*/
int function_get_shadows( const wchar_t *name );
/**
Creates a new function using the same definition as the specified function.
Returns non-zero if copy is successful.
*/
int function_copy( const wchar_t *name, const wchar_t *new_name );
/**
Returns whether this function shadows variables of the underlying function
*/
int function_get_shadows( const wchar_t *name );
#endif

View file

@ -184,7 +184,7 @@ void *halloc( void *context, size_t size )
#ifdef HALLOC_DEBUG
alloc_spill += parent->scratch_free;
#endif
res = calloc( 1, size + HALLOC_BLOCK_SIZE );
res = (char *)calloc( 1, size + HALLOC_BLOCK_SIZE );
if( !res )
DIE_MEM();
parent->scratch = (char *)res + size;
@ -192,11 +192,11 @@ void *halloc( void *context, size_t size )
}
else
{
res = calloc( 1, size );
res = (char *)calloc( 1, size );
if( !res )
DIE_MEM();
}
al_push_func( &parent->children, &late_free );
al_push_func( &parent->children, (void (*)())&late_free );
al_push( &parent->children, res );
}
@ -227,7 +227,7 @@ void halloc_register_function( void *context, void (*func)(void *), void *data )
return;
me = halloc_from_data( context );
al_push_func( &me->children, func );
al_push_func( &me->children, (void (*)())func );
al_push( &me->children, data );
}

View file

@ -33,7 +33,7 @@ void halloc_util_destroy()
array_list_t *al_halloc( void *context )
{
array_list_t *res = halloc( context, sizeof( array_list_t ) );
array_list_t *res = (array_list_t *)halloc( context, sizeof( array_list_t ) );
if( !res )
DIE_MEM();
al_init( res );
@ -43,7 +43,7 @@ array_list_t *al_halloc( void *context )
string_buffer_t *sb_halloc( void *context )
{
string_buffer_t *res = halloc( context, sizeof( string_buffer_t ) );
string_buffer_t *res = (string_buffer_t *)halloc( context, sizeof( string_buffer_t ) );
if( !res )
DIE_MEM();
sb_init( res );
@ -77,7 +77,7 @@ void *halloc_register( void *context, void *data )
wchar_t *halloc_wcsdup( void *context, const wchar_t *in )
{
size_t len=wcslen(in);
wchar_t *out = halloc( context, sizeof( wchar_t)*(len+1));
wchar_t *out = (wchar_t *)halloc( context, sizeof( wchar_t)*(len+1));
if( out == 0 )
{
@ -89,7 +89,7 @@ wchar_t *halloc_wcsdup( void *context, const wchar_t *in )
wchar_t *halloc_wcsndup( void * context, const wchar_t *in, int c )
{
wchar_t *res = halloc( context, sizeof(wchar_t)*(c+1) );
wchar_t *res = (wchar_t *)halloc( context, sizeof(wchar_t)*(c+1) );
if( res == 0 )
{
DIE_MEM();

View file

@ -41,15 +41,14 @@
*/
#define VAR_COUNT ( sizeof(highlight_var)/sizeof(wchar_t *) )
static void highlight_universal_internal( wchar_t * buff,
static void highlight_universal_internal( const wchar_t * buff,
int *color,
int pos,
array_list_t *error );
int pos );
/**
The environment variables used to specify the color of different tokens.
*/
static wchar_t *highlight_var[] =
static const wchar_t *highlight_var[] =
{
L"fish_color_normal",
L"fish_color_error",
@ -72,29 +71,24 @@ static wchar_t *highlight_var[] =
\return zero it this is not a valid prefix, non-zero otherwise
*/
static int is_potential_path( const wchar_t *path )
// PCA DOES_IO
static int is_potential_path( const wcstring &cpath )
{
wchar_t *tilde, *unescaped;
wchar_t *in, *out;
ASSERT_IS_BACKGROUND_THREAD();
const wchar_t *unescaped, *in;
wcstring cleaned_path;
int has_magic = 0;
int res = 0;
void *context = halloc( 0, 0 );
wcstring path(cpath);
expand_tilde(path);
unescape_string(path, 1);
unescaped = path.c_str();
tilde = expand_tilde( wcsdup(path) );
if( tilde )
{
halloc_register( context, tilde );
// debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped );
unescaped = unescape( tilde, 1 );
if( unescaped )
{
// debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped );
halloc_register( context, unescaped );
for( in = out = unescaped; *in; in++ )
for( in = unescaped; *in; in++ )
{
switch( *in )
{
@ -119,23 +113,22 @@ static int is_potential_path( const wchar_t *path )
default:
{
*(out++) = *in;
cleaned_path += *in;
break;
}
}
}
*out = 0;
if( !has_magic && wcslen( unescaped ) )
if( !has_magic && cleaned_path.length() )
{
int must_be_dir = 0;
DIR *dir;
must_be_dir = unescaped[wcslen(unescaped)-1] == L'/';
must_be_dir = cleaned_path[cleaned_path.length()-1] == L'/';
if( must_be_dir )
{
dir = wopendir( unescaped );
dir = wopendir( cleaned_path.c_str() );
res = !!dir;
if( dir )
{
@ -144,23 +137,19 @@ static int is_potential_path( const wchar_t *path )
}
else
{
wchar_t *dir_name, *base;
struct wdirent *ent;
wcstring dir_name = wdirname(cleaned_path);
wcstring base_name = wbasename(cleaned_path);
dir_name = wdirname( halloc_wcsdup(context, unescaped) );
base = wbasename( halloc_wcsdup(context, unescaped) );
if( (wcscmp( dir_name, L"/" ) == 0 ) &&
(wcscmp( base, L"/" ) == 0 ) )
if( dir_name == L"/" && base_name == L"/" )
{
res = 1;
}
else if( (dir = wopendir( dir_name )) )
else if( (dir = wopendir( dir_name.c_str() )) )
{
while( (ent = wreaddir( dir )) )
wcstring ent;
while (wreaddir(dir, ent))
{
if( wcsncmp( ent->d_name, base, wcslen(base) ) == 0 )
if( wcsncmp( base_name.c_str(), base_name.c_str(), base_name.length() ) == 0 )
{
res = 1;
break;
@ -172,10 +161,6 @@ static int is_potential_path( const wchar_t *path )
}
}
}
}
halloc_free( context );
return res;
@ -185,7 +170,7 @@ static int is_potential_path( const wchar_t *path )
int highlight_get_color( int highlight )
{
int i;
size_t i;
int idx=0;
int result = 0;
@ -545,19 +530,16 @@ static int has_expand_reserved( wchar_t *str )
}
void highlight_shell( wchar_t * buff,
int *color,
int pos,
array_list_t *error )
{
tokenizer tok;
// PCA DOES_IO
void tokenize( const wchar_t * const buff, int * const color, const int pos, array_list_t *error, void *context, const env_vars &vars) {
ASSERT_IS_BACKGROUND_THREAD();
int had_cmd=0;
int i;
int last_val;
wchar_t *last_cmd=0;
int len;
void *context;
wchar_t *cmd=0;
int accept_switches = 1;
@ -573,11 +555,10 @@ void highlight_shell( wchar_t * buff,
if( !len )
return;
context = halloc( 0, 0 );
for( i=0; buff[i] != 0; i++ )
color[i] = -1;
tokenizer tok;
for( tok_init( &tok, buff, TOK_SHOW_COMMENTS );
tok_has_next( &tok );
tok_next( &tok ) )
@ -715,7 +696,6 @@ void highlight_shell( wchar_t * buff,
if( !is_subcommand )
{
wchar_t *tmp;
/*
OK, this is a command, it has been
successfully expanded and everything
@ -732,7 +712,7 @@ void highlight_shell( wchar_t * buff,
is_cmd |= builtin_exists( cmd );
if( use_function )
is_cmd |= function_exists( cmd );
is_cmd |= function_exists_no_autoload( cmd );
/*
Moving on to expensive tests
@ -742,14 +722,20 @@ void highlight_shell( wchar_t * buff,
Check if this is a regular command
*/
if( use_command )
is_cmd |= !!(tmp=path_get_path( context, cmd ));
{
wcstring tmp;
is_cmd |= !!path_get_path_string( cmd, tmp, vars );
}
/*
Could not find the command. Maybe it is
a path for a implicit cd command.
*/
if( use_builtin || (use_function && function_exists( L"cd") ) )
is_cmd |= !!(tmp=path_get_cdpath( context, cmd ));
{
wcstring tmp;
is_cmd |= !!path_get_cdpath_string( cmd, tmp, vars );
}
if( is_cmd )
{
@ -917,8 +903,36 @@ void highlight_shell( wchar_t * buff,
}
}
}
tok_destroy( &tok );
}
// PCA DOES_IO (calls is_potential_path, path_get_path, maybe others)
void highlight_shell( const wchar_t *buff, int *color, int pos, array_list_t *error, const env_vars &vars )
{
ASSERT_IS_BACKGROUND_THREAD();
int i;
int len;
int last_val;
void *context;
CHECK( buff, );
CHECK( color, );
len = wcslen(buff);
if( !len )
return;
context = halloc( 0, 0 );
for( i=0; buff[i] != 0; i++ )
color[i] = -1;
/* Tokenize the string */
tokenize(buff, color, pos, error, context, vars);
/*
Locate and syntax highlight cmdsubsts recursively
@ -945,7 +959,7 @@ void highlight_shell( wchar_t * buff,
else
*end=0;
highlight_shell( begin+1, color +(begin-buffcpy)+1, -1, error );
highlight_shell( begin+1, color +(begin-buffcpy)+1, -1, error, vars );
color[end-buffcpy]=HIGHLIGHT_OPERATOR;
if( done )
@ -995,7 +1009,7 @@ void highlight_shell( wchar_t * buff,
}
highlight_universal_internal( buff, color, pos, error );
highlight_universal_internal( buff, color, pos );
/*
Spaces should not be highlighted at all, since it makes cursor look funky in some terminals
@ -1009,16 +1023,16 @@ void highlight_shell( wchar_t * buff,
}
halloc_free( context );
}
/**
Perform quote and parenthesis highlighting on the specified string.
*/
static void highlight_universal_internal( wchar_t * buff,
static void highlight_universal_internal( const wchar_t * buff,
int *color,
int pos,
array_list_t *error )
int pos )
{
if( (pos >= 0) && (pos < wcslen(buff)) )
@ -1036,7 +1050,7 @@ static void highlight_universal_internal( wchar_t * buff,
int level=0;
wchar_t prev_q=0;
wchar_t *str=buff;
const wchar_t *str=buff;
int match_found=0;
@ -1104,7 +1118,7 @@ static void highlight_universal_internal( wchar_t * buff,
wchar_t dec_char = *(wcschr( L"()[]{}", buff[pos] ) + step);
wchar_t inc_char = buff[pos];
int level = 0;
wchar_t *str = &buff[pos];
const wchar_t *str = &buff[pos];
int match_found=0;
while( (str >= buff) && *str)
@ -1130,15 +1144,12 @@ static void highlight_universal_internal( wchar_t * buff,
}
}
void highlight_universal( wchar_t * buff,
int *color,
int pos,
array_list_t *error )
void highlight_universal( const wchar_t *buff, int *color, int pos, array_list_t *error, const env_vars &vars )
{
int i;
for( i=0; buff[i]; i++ )
color[i] = 0;
highlight_universal_internal( buff, color, pos, error );
highlight_universal_internal( buff, color, pos );
}

View file

@ -7,6 +7,7 @@
#include <wchar.h>
#include "env.h"
#include "util.h"
/**
@ -72,7 +73,7 @@
\param pos the cursor position. Used for quote matching, etc.
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
*/
void highlight_shell( wchar_t * buff, int *color, int pos, array_list_t *error );
void highlight_shell( const wchar_t *, int *, int, array_list_t *, const env_vars &vars );
/**
Perform syntax highlighting for the text in buff. Matching quotes and paranthesis are highlighted. The result is
@ -84,7 +85,7 @@ void highlight_shell( wchar_t * buff, int *color, int pos, array_list_t *error )
\param pos the cursor position. Used for quote matching, etc.
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
*/
void highlight_universal( wchar_t * buff, int *color, int pos, array_list_t *error );
void highlight_universal( const wchar_t *, int *, int, array_list_t *, const env_vars &vars );
/**
Translate from HIGHLIGHT_* to FISH_COLOR_* according to environment

View file

@ -426,7 +426,7 @@ static void history_destroy_mode_wrapper( void *n, history_mode_t *m )
*/
static history_mode_t *history_create_mode( const wchar_t *name )
{
history_mode_t *new_mode = halloc( 0, sizeof( history_mode_t ));
history_mode_t *new_mode = (history_mode_t *)halloc( 0, sizeof( history_mode_t ));
new_mode->name = intern(name);
@ -474,7 +474,7 @@ static wchar_t *history_filename( void *context, const wchar_t *name, const wcha
if( !path )
return 0;
res = wcsdupcat( path, L"/", name, L"_history", suffix?suffix:(void *)0);
res = wcsdupcat( path, L"/", name, L"_history", suffix?suffix:NULL);
halloc_register_function( context, &free, res );
return res;
}
@ -510,7 +510,7 @@ static void history_populate_from_mmap( history_mode_t *m )
i = item_get( m, pos );
if( (i_orig=hash_get( &current_mode->session_item, i ) ) )
if( (i_orig=(item_t *)hash_get( &current_mode->session_item, i ) ) )
{
/*
This item comes from this session. Insert the
@ -592,7 +592,7 @@ static void history_load( history_mode_t *m )
m->mmap_length = (size_t)len;
if( lseek( fd, 0, SEEK_SET ) == 0 )
{
if( (m->mmap_start = mmap( 0, m->mmap_length, PROT_READ, MAP_PRIVATE, fd, 0 )) != MAP_FAILED )
if( (m->mmap_start = (char *)mmap( 0, m->mmap_length, PROT_READ, MAP_PRIVATE, fd, 0 )) != MAP_FAILED )
{
ok = 1;
history_populate_from_mmap( m );
@ -761,7 +761,7 @@ void history_add( const wchar_t *str )
if( !current_mode )
return;
i = halloc( current_mode->item_context, sizeof(item_t));
i = (item_t *)halloc( current_mode->item_context, sizeof(item_t));
i->data = (wchar_t *)halloc_wcsdup( current_mode->item_context, str );
i->timestamp = time(0);
@ -955,7 +955,7 @@ void history_set_mode( const wchar_t *name )
{
if( !mode_table )
{
mode_table = malloc( sizeof(hash_table_t ));
mode_table = (hash_table_t *)malloc( sizeof(hash_table_t ));
hash_init( mode_table, &hash_wcs_func, &hash_wcs_cmp );
}

View file

@ -74,7 +74,7 @@
*/
#define TERMINFO_ADD(key) \
{ \
terminfo_mapping_t *m = halloc( terminfo_mappings, sizeof( terminfo_mapping_t ) ); \
terminfo_mapping_t *m = (terminfo_mapping_t *)halloc( terminfo_mappings, sizeof( terminfo_mapping_t ) ); \
m->name = halloc_wcsdup( terminfo_mappings, (L ## #key)+4 ); \
m->seq = key; \
al_push( terminfo_mappings, m ); \
@ -277,7 +277,7 @@ void input_mapping_add( const wchar_t *sequence,
}
}
input_mapping_t *m = malloc( sizeof( input_mapping_t ) );
input_mapping_t *m = (input_mapping_t *)malloc( sizeof( input_mapping_t ) );
m->seq = intern( sequence );
m->command = intern(command);
al_push( &mappings, m );

View file

@ -39,7 +39,7 @@ const wchar_t *intern( const wchar_t *in )
if( !intern_table )
{
intern_table = malloc( sizeof( hash_table_t ) );
intern_table = (hash_table_t *)malloc( sizeof( hash_table_t ) );
if( !intern_table )
{
DIE_MEM();
@ -49,12 +49,12 @@ const wchar_t *intern( const wchar_t *in )
if( intern_static_table )
{
res = hash_get( intern_static_table, in );
res = (const wchar_t *)hash_get( intern_static_table, in );
}
if( !res )
{
res = hash_get( intern_table, in );
res = (const wchar_t *)hash_get( intern_table, in );
if( !res )
{
@ -80,7 +80,7 @@ const wchar_t *intern_static( const wchar_t *in )
if( !intern_static_table )
{
intern_static_table = malloc( sizeof( hash_table_t ) );
intern_static_table = (hash_table_t *)malloc( sizeof( hash_table_t ) );
if( !intern_static_table )
{
DIE_MEM();
@ -88,7 +88,7 @@ const wchar_t *intern_static( const wchar_t *in )
hash_init( intern_static_table, &hash_wcs_func, &hash_wcs_cmp );
}
res = hash_get( intern_static_table, in );
res = (const wchar_t *)hash_get( intern_static_table, in );
if( !res )
{

6
io.cpp
View file

@ -102,11 +102,11 @@ void io_buffer_read( io_data_t *d )
io_data_t *io_buffer_create( int is_input )
{
io_data_t *buffer_redirect = malloc( sizeof( io_data_t ));
io_data_t *buffer_redirect = (io_data_t *)malloc( sizeof( io_data_t ));
buffer_redirect->io_mode=IO_BUFFER;
buffer_redirect->next=0;
buffer_redirect->param2.out_buffer= malloc( sizeof(buffer_t));
buffer_redirect->param2.out_buffer= (buffer_t *)malloc( sizeof(buffer_t));
buffer_redirect->is_input = is_input;
b_init( buffer_redirect->param2.out_buffer );
buffer_redirect->fd=is_input?0:1;
@ -202,7 +202,7 @@ io_data_t *io_duplicate( void *context, io_data_t *l )
if( l == 0 )
return 0;
res = halloc( context, sizeof( io_data_t) );
res = (io_data_t *)halloc( context, sizeof( io_data_t) );
if( !res )
{

View file

@ -59,7 +59,7 @@ static int has_xsel()
res = !!path;
halloc_free( context );
called = 1;
}
}
return res;
}
@ -74,13 +74,13 @@ static void kill_add_internal( wchar_t *str )
if( kill_last == 0 )
{
kill_current = kill_last=malloc( sizeof( ll_node_t ) );
kill_current = kill_last=(ll_node_t *)malloc( sizeof( ll_node_t ) );
kill_current->data = wcsdup(str);
kill_current->prev = kill_current;
}
else
{
kill_current = malloc( sizeof( ll_node_t ) );
kill_current = (ll_node_t *)malloc( sizeof( ll_node_t ) );
kill_current->data = kill_last->data;
kill_last->data = wcsdup(str);
kill_current->prev = kill_last->prev;
@ -195,10 +195,10 @@ static void kill_remove( wchar_t *s )
void kill_replace( wchar_t *old, wchar_t *new )
void kill_replace( wchar_t *old, wchar_t *newv )
{
kill_remove( old );
kill_add( new );
kill_add( newv );
}
wchar_t *kill_yank_rotate()

2
kill.h
View file

@ -12,7 +12,7 @@
/**
Replace the specified string in the killring
*/
void kill_replace( wchar_t *old, wchar_t *new );
void kill_replace( wchar_t *old, wchar_t *newv );
/**

View file

@ -242,7 +242,7 @@ static char *file_exists( const char *dir, const char *in )
{
int dir_len = strlen( dir );
int need_sep = dir[dir_len - 1] != '/';
char *filename = my_malloc( dir_len + need_sep + strlen( in ) + 1 );
char *filename = (char *)my_malloc( dir_len + need_sep + strlen( in ) + 1 );
char *replaceme;
struct stat buf;
@ -307,7 +307,7 @@ static int append_filenames( array_list_t *list, char *f, int all )
if (xdg_data_home)
{
result = file_exists( xdg_data_home, f );
if ( result )
if (result)
{
al_push( list, result );
if ( !all )
@ -323,7 +323,7 @@ static int append_filenames( array_list_t *list, char *f, int all )
{
char *guessed_xdg_home;
guessed_xdg_home = my_malloc (strlen (home) + strlen ("/.local/share") + 1);
guessed_xdg_home = (char *)my_malloc (strlen (home) + strlen ("/.local/share") + 1);
if( !guessed_xdg_home )
return 0;
@ -332,7 +332,7 @@ static int append_filenames( array_list_t *list, char *f, int all )
result = file_exists( guessed_xdg_home, f );
free (guessed_xdg_home);
if ( result )
if (result)
{
al_push( list, result );
if ( !all )
@ -364,7 +364,7 @@ static int append_filenames( array_list_t *list, char *f, int all )
}
len = end_ptr - ptr;
dir = my_malloc (len + 1);
dir = (char *)my_malloc (len + 1);
if( !dir )
return 0;
@ -374,7 +374,7 @@ static int append_filenames( array_list_t *list, char *f, int all )
free (dir);
if ( result )
if (result)
{
al_push( list, result );
if ( !all ) {
@ -397,7 +397,7 @@ static char *get_filename( char *f )
al_init( &list );
append_filenames( &list, f, 0 );
first = al_pop( &list );
first = (char *)al_pop( &list );
al_destroy( &list );
return first;
}
@ -409,7 +409,7 @@ static char *get_filename( char *f )
*/
static char *munge( char *in )
{
char *out = my_malloc( strlen( in )+1 );
char *out = (char *)my_malloc( strlen( in )+1 );
char *p=out;
int had_whitespace = 0;
int printed = 0;
@ -529,8 +529,8 @@ static char *get_description( const char *mimetype )
snprintf( buff, BUFF_SIZE, START_TAG, lang, lang );
start_re = my_malloc( sizeof(regex_t));
stop_re = my_malloc( sizeof(regex_t));
start_re = (regex_t *)my_malloc( sizeof(regex_t));
stop_re = (regex_t *)my_malloc( sizeof(regex_t));
int reg_status;
if( ( reg_status = regcomp( start_re, buff, REG_EXTENDED ) ) )
@ -560,7 +560,7 @@ static char *get_description( const char *mimetype )
}
}
fn_part = my_malloc( strlen(MIME_DIR) + strlen( mimetype) + strlen(MIME_SUFFIX) + 1 );
fn_part = (char *)my_malloc( strlen(MIME_DIR) + strlen( mimetype) + strlen(MIME_SUFFIX) + 1 );
if( !fn_part )
{
@ -597,7 +597,7 @@ static char *get_description( const char *mimetype )
return 0;
}
contents = my_malloc( st.st_size + 1 );
contents = (char *)my_malloc( st.st_size + 1 );
if( !contents )
{
return 0;
@ -692,7 +692,7 @@ static char *get_action( const char *mimetype )
for ( i = 0; i < al_get_count( &mime_filenames ); i++ )
{
launcher_str = search_ini( al_get( &mime_filenames, i ), mimetype );
launcher_str = (char *)search_ini( (char *)al_get( &mime_filenames, i ), mimetype );
if ( launcher_str )
break;
}
@ -747,7 +747,7 @@ static char *get_action( const char *mimetype )
if( end )
*end = '\0';
launcher_full = my_malloc( strlen( launcher) + strlen( APPLICATIONS_DIR)+1 );
launcher_full = (char *)my_malloc( strlen( launcher) + strlen( APPLICATIONS_DIR)+1 );
if( !launcher_full )
{
free( launcher_str );
@ -797,7 +797,7 @@ static void writer( char c )
if( launch_len <= launch_pos )
{
int new_len = launch_len?2*launch_len:256;
char *new_buff = realloc( launch_buff, new_len );
char *new_buff = (char *)realloc( launch_buff, new_len );
if( !new_buff )
{
free( launch_buff );
@ -866,7 +866,7 @@ static char *get_fullfile( char *file )
int l = strlen(cwd);
fullfile = my_malloc( l + strlen(file)+2 );
fullfile = (char *)my_malloc( l + strlen(file)+2 );
if( !fullfile )
{
free(cwd);
@ -1430,7 +1430,7 @@ int main (int argc, char *argv[])
if( !l )
{
l = my_malloc( sizeof( array_list_t ) );
l = (array_list_t *)my_malloc( sizeof( array_list_t ) );
if( l == 0 )
{
break;

View file

@ -445,7 +445,7 @@ void writestr( const wchar_t *str )
halloc_register_function_void( global_context, &output_destroy );
}
writestr_buff = realloc( writestr_buff, len );
writestr_buff = (char *)realloc( writestr_buff, len );
if( !writestr_buff )
{
DIE_MEM();
@ -594,7 +594,7 @@ void output_set_term( wchar_t *term )
wchar_t *output_get_term()
{
return current_term ? current_term : L"<unknown>";
return (wchar_t *)(current_term ? current_term : L"<unknown>");
}

View file

@ -781,7 +781,7 @@ static void parse_util_autounload( const wchar_t *path_var_name,
for( i=0; i<al_get_count( &key ); i++ )
{
wchar_t *item = (wchar_t *)al_get( &key, i );
time_t *tm = hash_get( &loaded->load_time, item );
time_t *tm = (time_t *)hash_get( &loaded->load_time, item );
if( wcscmp( item, skip ) == 0 )
{
@ -859,7 +859,7 @@ int parse_util_load( const wchar_t *cmd,
*/
if( !all_loaded )
{
all_loaded = malloc( sizeof( hash_table_t ) );
all_loaded = (hash_table_t *)malloc( sizeof( hash_table_t ) );
halloc_register_function_void( global_context, &parse_util_destroy );
if( !all_loaded )
{
@ -904,7 +904,7 @@ int parse_util_load( const wchar_t *cmd,
set up initial data
*/
// debug( 0, L"Create brand new autoload_t for %ls->%ls", path_var_name, path_var );
loaded = malloc( sizeof( autoload_t ) );
loaded = (autoload_t *)malloc( sizeof( autoload_t ) );
if( !loaded )
{
DIE_MEM();
@ -918,7 +918,7 @@ int parse_util_load( const wchar_t *cmd,
}
path_list = al_new( global_context);
path_list = (array_list_t *)al_new();
tokenize_variable_array( path_var, path_list );
@ -1014,7 +1014,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
struct stat buf;
wchar_t *next = (wchar_t *)al_get( path_list, i );
sb_clear( path );
sb_append( path, next, L"/", cmd, L".fish", (void *)0 );
sb_append( path, next, L"/", cmd, L".fish", NULL );
if( (wstat( (wchar_t *)path->buff, &buf )== 0) &&
(waccess( (wchar_t *)path->buff, R_OK ) == 0) )
@ -1027,7 +1027,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
if( !tm )
{
tm = malloc(sizeof(time_t)*2);
tm = (time_t *)malloc(sizeof(time_t)*2);
if( !tm )
{
DIE_MEM();
@ -1078,7 +1078,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
*/
if( !tm )
{
tm = malloc(sizeof(time_t)*2);
tm = (time_t *)malloc(sizeof(time_t)*2);
if( !tm )
{
DIE_MEM();
@ -1124,7 +1124,7 @@ void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments )
for( i=0, arg=argv; i < al_get_count( named_arguments ); i++ )
{
env_set( al_get( named_arguments, i ), *arg, ENV_LOCAL );
env_set( (const wchar_t *)al_get( named_arguments, i ), *arg, ENV_LOCAL );
if( *arg )
arg++;

View file

@ -448,27 +448,27 @@ static int block_count( block_t *b )
void parser_push_block( int type )
{
block_t *new = halloc( 0, sizeof( block_t ));
block_t *newv = (block_t *)halloc( 0, sizeof( block_t ));
new->src_lineno = parser_get_lineno();
new->src_filename = parser_current_filename()?intern(parser_current_filename()):0;
newv->src_lineno = parser_get_lineno();
newv->src_filename = parser_current_filename()?intern(parser_current_filename()):0;
new->outer = current_block;
new->type = (current_block && current_block->skip)?FAKE:type;
newv->outer = current_block;
newv->type = (current_block && current_block->skip)?FAKE:type;
/*
New blocks should be skipped if the outer block is skipped,
except TOP ans SUBST block, which open up new environments. Fake
blocks should always be skipped. Rather complicated... :-(
*/
new->skip=current_block?current_block->skip:0;
newv->skip=current_block?current_block->skip:0;
/*
Type TOP and SUBST are never skipped
*/
if( type == TOP || type == SUBST )
{
new->skip = 0;
newv->skip = 0;
}
/*
@ -476,17 +476,17 @@ void parser_push_block( int type )
*/
if( type == FAKE || type == FUNCTION_DEF )
{
new->skip = 1;
newv->skip = 1;
}
new->job = 0;
new->loop_status=LOOP_NORMAL;
newv->job = 0;
newv->loop_status=LOOP_NORMAL;
current_block = new;
current_block = newv;
if( (new->type != FUNCTION_DEF) &&
(new->type != FAKE) &&
(new->type != TOP) )
if( (newv->type != FUNCTION_DEF) &&
(newv->type != FAKE) &&
(newv->type != TOP) )
{
env_push( type == FUNCTION_CALL );
halloc_register_function_void( current_block, &env_pop );
@ -1009,7 +1009,7 @@ void parser_stack_trace( block_t *b, string_buffer_t *buff)
for( i=1; b->param2.function_call_process->argv[i]; i++ )
{
sb_append( &tmp, i>1?L" ":L"", b->param2.function_call_process->argv[i], (void *)0 );
sb_append( &tmp, i>1?L" ":L"", b->param2.function_call_process->argv[i], NULL );
}
sb_printf( buff, _(L"\twith parameter list '%ls'\n"), (wchar_t *)tmp.buff );
@ -1154,7 +1154,7 @@ wchar_t *parser_current_line()
if( !lineinfo )
{
lineinfo = malloc( sizeof(string_buffer_t) );
lineinfo = (string_buffer_t *)malloc( sizeof(string_buffer_t) );
sb_init( lineinfo );
}
sb_clear( lineinfo );
@ -1342,7 +1342,7 @@ static void parse_job_argument_list( process_t *p,
if( !p->argv )
halloc_register( j, p->argv = list_to_char_arr( args ) );
p->next = halloc( j, sizeof( process_t ) );
p->next = (process_t *)halloc( j, sizeof( process_t ) );
tok_next( tok );
@ -1393,7 +1393,7 @@ static void parse_job_argument_list( process_t *p,
*/
if( (current_block->type == SWITCH) &&
(wcscmp( al_get( args, 0), L"case" )==0) &&
(wcscmp( (const wchar_t *)al_get( args, 0), L"case" )==0) &&
p->type == INTERNAL_BUILTIN )
{
skip=0;
@ -1490,7 +1490,7 @@ static void parse_job_argument_list( process_t *p,
break;
}
new_io = halloc( j, sizeof(io_data_t) );
new_io = (io_data_t *)halloc( j, sizeof(io_data_t) );
if( !new_io )
DIE_MEM();
@ -1681,7 +1681,7 @@ static void parse_job_argument_list( process_t *p,
\param p The process structure that should be used to represent the first process in the job.
\param j The job structure to contain the parsed job
\param tok tokenizer to read from
f
\return 1 on success, 0 on error
*/
static int parse_job( process_t *p,
@ -2303,7 +2303,7 @@ static void eval_job( tokenizer *tok )
if( profile )
{
p=malloc( sizeof(profile_element_t));
p=(profile_element_t*)malloc( sizeof(profile_element_t));
if( !p )
DIE_MEM();
p->cmd=0;
@ -2339,7 +2339,7 @@ static void eval_job( tokenizer *tok )
}
}
j->first_process = halloc( j, sizeof( process_t ) );
j->first_process = (process_t *)halloc( j, sizeof( process_t ) );
job_begin_pos = tok_get_pos( tok );
@ -2539,7 +2539,7 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type )
parser_push_block( block_type );
current_tokenizer = malloc( sizeof(tokenizer));
current_tokenizer = (tokenizer *)malloc( sizeof(tokenizer));
tok_init( current_tokenizer, cmd, 0 );
error_code = 0;
@ -2858,6 +2858,8 @@ int parser_test( const wchar_t * buff,
string_buffer_t *out,
const wchar_t *prefix )
{
ASSERT_IS_MAIN_THREAD();
tokenizer tok;
/*
Set to one if a command name has been given for the currently

182
path.cpp
View file

@ -25,7 +25,108 @@
*/
#define MISSING_COMMAND_ERR_MSG _( L"Error while searching for command '%ls'" )
bool path_get_path_string(const wcstring &cmd_str, wcstring &output, const env_vars &vars)
{
const wchar_t * const cmd = cmd_str.c_str();
int err = ENOENT;
debug( 3, L"path_get_path_string( '%ls' )", cmd );
if(wcschr( cmd, L'/' ) != 0 )
{
if( waccess( cmd, X_OK )==0 )
{
struct stat buff;
if(wstat( cmd, &buff ))
{
return false;
}
if (S_ISREG(buff.st_mode))
{
output = cmd_str;
return true;
}
else
{
errno = EACCES;
return false;
}
}
else
{
//struct stat buff;
//wstat( cmd, &buff );
return false;
}
}
else
{
const wchar_t *path = vars.get(L"PATH");
if( path == 0 )
{
if( contains( PREFIX L"/bin", L"/bin", L"/usr/bin" ) )
{
path = L"/bin" ARRAY_SEP_STR L"/usr/bin";
}
else
{
path = L"/bin" ARRAY_SEP_STR L"/usr/bin" ARRAY_SEP_STR PREFIX L"/bin";
}
}
wcstokenizer tokenizer(path, ARRAY_SEP_STR);
wcstring new_cmd;
while (tokenizer.next(new_cmd))
{
size_t path_len = new_cmd.size();
if (path_len == 0) continue;
append_path_component(new_cmd, cmd_str);
if( waccess( new_cmd.c_str(), X_OK )==0 )
{
struct stat buff;
if( wstat( new_cmd.c_str(), &buff )==-1 )
{
if( errno != EACCES )
{
wperror( L"stat" );
}
continue;
}
if( S_ISREG(buff.st_mode) )
{
output = new_cmd;
return true;
}
err = EACCES;
}
else
{
switch( errno )
{
case ENOENT:
case ENAMETOOLONG:
case EACCES:
case ENOTDIR:
break;
default:
{
debug( 1,
MISSING_COMMAND_ERR_MSG,
new_cmd.c_str() );
wperror( L"access" );
}
}
}
}
}
errno = err;
return false;
}
wchar_t *path_get_path( void *context, const wchar_t *cmd )
{
@ -81,7 +182,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
/*
Allocate string long enough to hold the whole command
*/
wchar_t *new_cmd = halloc( context, sizeof(wchar_t)*(wcslen(cmd)+wcslen(path)+2) );
wchar_t *new_cmd = (wchar_t *)halloc( context, sizeof(wchar_t)*(wcslen(cmd)+wcslen(path)+2) );
/*
We tokenize a copy of the path, since strtok modifies
@ -154,7 +255,82 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
}
wchar_t *path_get_cdpath( void *context, wchar_t *dir )
bool path_get_cdpath_string(const wcstring &dir_str, wcstring &result, const env_vars &vars)
{
wchar_t *res = 0;
int err = ENOENT;
bool success = false;
const wchar_t *const dir = dir_str.c_str();
if( dir[0] == L'/'|| (wcsncmp( dir, L"./", 2 )==0) )
{
struct stat buf;
if( wstat( dir, &buf ) == 0 )
{
if( S_ISDIR(buf.st_mode) )
{
result = dir_str;
success = true;
}
else
{
err = ENOTDIR;
}
}
}
else
{
const wchar_t *path = vars.get(L"CDPATH");
if( !path || !wcslen(path) )
{
path = L".";
}
wcstokenizer tokenizer(path, ARRAY_SEP_STR);
wcstring next_path;
while (tokenizer.next(next_path))
{
expand_tilde(next_path);
if (next_path.size() == 0) continue;
wcstring whole_path = next_path;
append_path_component(whole_path, dir);
struct stat buf;
if( wstat( whole_path.c_str(), &buf ) == 0 )
{
if( S_ISDIR(buf.st_mode) )
{
result = whole_path;
success = true;
break;
}
else
{
err = ENOTDIR;
}
}
else
{
if( lwstat( whole_path.c_str(), &buf ) == 0 )
{
err = EROTTEN;
}
}
}
}
if( !success )
{
errno = err;
}
return res;
}
wchar_t *path_get_cdpath( void *context, const wchar_t *dir )
{
wchar_t *res = 0;
int err = ENOENT;
@ -205,7 +381,7 @@ wchar_t *path_get_cdpath( void *context, wchar_t *dir )
nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
{
wchar_t *expanded_path = expand_tilde( wcsdup(nxt_path) );
wchar_t *expanded_path = expand_tilde_compat( wcsdup(nxt_path) );
// debug( 2, L"woot %ls\n", expanded_path );

6
path.h
View file

@ -32,6 +32,9 @@ wchar_t *path_get_config( void *context);
*/
wchar_t *path_get_path( void *context, const wchar_t *cmd );
class env_vars;
bool path_get_path_string(const wcstring &cmd, wcstring &output, const env_vars &vars);
/**
Returns the full path of the specified directory, using the CDPATH
variable as a list of base directories for relative paths. The
@ -49,7 +52,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd );
\param context the halloc context to use for memory allocations
\return 0 if the command can not be found, the path of the command otherwise.
*/
wchar_t *path_get_cdpath( void *context, wchar_t *in );
wchar_t *path_get_cdpath( void *context, const wchar_t *in );
bool path_get_cdpath_string(const wcstring &in, wcstring &out, const env_vars &vars);
/**
Remove doulbe slashes and trailing slashes from a path,

View file

@ -204,7 +204,7 @@ job_t *job_create()
while( job_get( free_id ) != 0 )
free_id++;
res = halloc( 0, sizeof(job_t) );
res = (job_t *)halloc( 0, sizeof(job_t) );
res->next = first_job;
res->job_id = free_id;
first_job = res;

View file

@ -101,6 +101,7 @@ commence.
#include "screen.h"
#include "halloc.h"
#include "halloc_util.h"
#include "iothread.h"
#include "parse_util.h"
@ -262,10 +263,7 @@ typedef struct reader_data
/**
Function for syntax highlighting
*/
void (*highlight_func)( wchar_t *,
int *,
int,
array_list_t * );
highlight_function_t highlight_function;
/**
Function for testing if the string can be returned
@ -436,9 +434,9 @@ static void reader_repaint()
/**
Internal helper function for handling killing parts of text.
*/
static void reader_kill( wchar_t *begin, int length, int mode, int new )
static void reader_kill( wchar_t *begin, int length, int mode, int newv )
{
if( new )
if( newv )
{
sb_clear( &data->kill_item );
sb_append_substring( &data->kill_item, begin, length );
@ -523,13 +521,13 @@ static int check_size()
{
data->buff_sz = maxi( 128, data->buff_len*2 );
data->buff = realloc( data->buff,
data->buff = (wchar_t *)realloc( data->buff,
sizeof(wchar_t)*data->buff_sz);
data->color = realloc( data->color,
data->color = (int *)realloc( data->color,
sizeof(int)*data->buff_sz);
data->indent = realloc( data->indent,
data->indent = (int *)realloc( data->indent,
sizeof(int)*data->buff_sz);
if( data->buff==0 ||
@ -606,7 +604,7 @@ int reader_interrupted()
void reader_write_title()
{
wchar_t *title;
const wchar_t *title;
array_list_t l;
wchar_t *term = env_get( L"TERM" );
@ -647,7 +645,7 @@ void reader_write_title()
title = function_exists( L"fish_title" )?L"fish_title":DEFAULT_TITLE;
if( wcslen( title ) == 0 )
if( wcslen( title ) ==0 )
return;
al_init( &l );
@ -1079,7 +1077,7 @@ static void completion_insert( const wchar_t *val, int flags )
wchar_t *pout;
replaced = pout =
malloc( sizeof(wchar_t)*(wcslen(val) + 1) );
(wchar_t *)malloc( sizeof(wchar_t)*(wcslen(val) + 1) );
for( pin=val; *pin; pin++ )
{
@ -1562,7 +1560,7 @@ static int handle_completions( array_list_t *comp )
if( len <= PREFIX_MAX_LEN )
{
prefix = malloc( sizeof(wchar_t)*(len+1) );
prefix = (wchar_t *)malloc( sizeof(wchar_t)*(len+1) );
wcslcpy( prefix, prefix_start, len );
prefix[len]=L'\0';
}
@ -1797,7 +1795,7 @@ static int contains_al( const wchar_t *needle,
int i;
for( i=0; i<al_get_count( haystack ); i++ )
{
if( !wcscmp( needle, al_get( haystack, i ) ) )
if( !wcscmp( needle, (const wchar_t *)al_get( haystack, i ) ) )
return 1;
}
return 0;
@ -1910,7 +1908,7 @@ static void handle_token_history( int forward, int reset )
return, otherwise add it.
*/
const wchar_t *last = al_get( &data->search_prev, al_get_count( &data->search_prev ) -1 );
const wchar_t *last = (const wchar_t *)al_get( &data->search_prev, al_get_count( &data->search_prev ) -1 );
if( wcscmp( last, (wchar_t *)data->search_buff.buff ) )
{
str = wcsdup( (wchar_t *)data->search_buff.buff );
@ -1983,7 +1981,7 @@ static void handle_token_history( int forward, int reset )
\param erase Whether to erase the characters along the way or only move past them.
\param new if the new kill item should be appended to the previous kill item or not.
*/
static void move_word( int dir, int erase, int new )
static void move_word( int dir, int erase, int newv )
{
int end_buff_pos=data->buff_pos;
int step = dir?1:-1;
@ -2112,7 +2110,7 @@ static void move_word( int dir, int erase, int new )
int first_char = mini( data->buff_pos, end_buff_pos );
// fwprintf( stderr, L"Remove from %d to %d\n", first_char, first_char+remove_count );
reader_kill( data->buff + first_char, remove_count, dir?KILL_APPEND:KILL_PREPEND, new );
reader_kill( data->buff + first_char, remove_count, dir?KILL_APPEND:KILL_PREPEND, newv );
}
else
@ -2123,12 +2121,13 @@ static void move_word( int dir, int erase, int new )
}
wchar_t *reader_get_buffer()
wchar_t *reader_get_buffer(void)
{
return data?data->buff:0;
ASSERT_IS_MAIN_THREAD();
return data?data->buff:NULL;
}
void reader_set_buffer( wchar_t *b, int p )
void reader_set_buffer( const wchar_t *b, int p )
{
int l = wcslen( b );
@ -2266,9 +2265,9 @@ static int default_test( wchar_t *b )
return 0;
}
void reader_push( wchar_t *name )
void reader_push( const wchar_t *name )
{
reader_data_t *n = calloc( 1, sizeof( reader_data_t ) );
reader_data_t *n = (reader_data_t *)calloc( 1, sizeof( reader_data_t ) );
if( !n )
{
@ -2349,7 +2348,7 @@ void reader_pop()
}
}
void reader_set_prompt( wchar_t *new_prompt )
void reader_set_prompt( const wchar_t *new_prompt )
{
free( data->prompt );
data->prompt=wcsdup(new_prompt);
@ -2361,12 +2360,9 @@ void reader_set_complete_function( void (*f)( const wchar_t *,
data->complete_func = f;
}
void reader_set_highlight_function( void (*f)( wchar_t *,
int *,
int,
array_list_t * ) )
void reader_set_highlight_function( highlight_function_t func )
{
data->highlight_func = f;
data->highlight_function = func;
}
void reader_set_test_function( int (*f)( wchar_t * ) )
@ -2374,6 +2370,98 @@ void reader_set_test_function( int (*f)( wchar_t * ) )
data->test_func = f;
}
/** A class as the context pointer for a background (threaded) highlight operation. */
class background_highlight_context {
public:
/**
The string to highlight
*/
wcstring buff;
/**
Malloc'd color buffer (same size as buff)
*/
int *color;
/**
The position to use for bracket matching
*/
int match_highlight_pos;
/**
Function for syntax highlighting
*/
highlight_function_t highlight_function;
/**
Environment variables
*/
env_vars vars;
/**
When the request was made
*/
double when;
background_highlight_context() : vars(env_vars::highlighting_keys)
{
}
~background_highlight_context()
{
free(color);
}
};
static void highlight_complete2( wchar_t *command, const int *colors, int position, void *ctx_ptr ) {
background_highlight_context *ctx = (background_highlight_context *)ctx_ptr;
if (ctx->buff == data->buff) {
/* The data hasn't changed, so swap in our colors */
free(data->color);
data->color = ctx->color;
ctx->color = NULL;
data->repaint_needed = 1;
}
/* Free our context */
delete ctx;
}
static void highlight_complete(void *ctx_ptr, int result) {
background_highlight_context *ctx = (background_highlight_context *)ctx_ptr;
if (ctx->buff == data->buff) {
/* The data hasn't changed, so swap in our colors */
free(data->color);
data->color = ctx->color;
ctx->color = NULL;
//data->repaint_needed = 1;
//s_reset( &data->screen, 1 );
reader_repaint();
}
/* Free our context */
delete ctx;
}
static int threaded_highlight(void *ctx_ptr) {
background_highlight_context *ctx = (background_highlight_context *)ctx_ptr;
array_list_t *error = 0;
const wchar_t *delayer = ctx->vars.get(L"HIGHLIGHT_DELAY");
double secDelay = 0;
if (delayer) {
wcstring tmp = delayer;
secDelay = from_string<double>(tmp);
}
if (secDelay > 0) usleep((useconds_t)(secDelay * 1E6));
//write(0, "Start", 5);
ctx->highlight_function( ctx->buff.c_str(), ctx->color, ctx->match_highlight_pos, error, ctx->vars );
//write(0, "End", 3);
return 0;
}
/**
Call specified external highlighting function and then do search
highlighting. Lastly, clear the background color under the cursor
@ -2385,7 +2473,24 @@ void reader_set_test_function( int (*f)( wchar_t * ) )
*/
static void reader_super_highlight_me_plenty( int match_highlight_pos, array_list_t *error )
{
data->highlight_func( data->buff, data->color, match_highlight_pos, error );
/* Ensure we don't repaint with stale data */
size_t i;
for (i=0; i < data->buff_sz; i++) {
data->color[i] = HIGHLIGHT_NORMAL;
}
background_highlight_context *ctx = new background_highlight_context;
ctx->buff = data->buff;
ctx->color = (int *)calloc(data->buff_sz, sizeof *ctx->color);
ctx->match_highlight_pos = match_highlight_pos;
ctx->highlight_function = data->highlight_function;
ctx->when = timef();
#if 1
iothread_perform(threaded_highlight, highlight_complete, ctx);
#else
data->highlight_function( ctx->buff, ctx->color, match_highlight_pos, error, highlight_complete2, ctx );
#endif
if( wcslen((wchar_t *)data->search_buff.buff) )
{

View file

@ -86,7 +86,7 @@ wchar_t *reader_get_buffer();
\param b the new buffer value
\param p the cursor position. If \c p is less than zero, the cursor is placed on the last character.
*/
void reader_set_buffer( wchar_t *b, int p );
void reader_set_buffer( const wchar_t *b, int p );
/**
Get the current cursor position in the command line. If interactive
@ -110,7 +110,7 @@ wchar_t *reader_readline();
/**
Push a new reader environment.
*/
void reader_push( wchar_t *name );
void reader_push( const wchar_t *name );
/**
Return to previous reader environment
@ -126,14 +126,23 @@ void reader_pop();
void reader_set_complete_function( void (*f)( const wchar_t *, array_list_t * ) );
/**
<<<<<<< upstream
=======
The type of a highlight function.
*/
class env_vars;
typedef void (*highlight_function_t)( const wchar_t *, int *, int, array_list_t *, const env_vars &vars );
/**
>>>>>>> HEAD~2
Specify function for syntax highlighting. The function must take these arguments:
- The command to be highlighted as a null terminated array of wchar_t
- The color code of each character as an array of ints
- The cursor position
- An array_list_t used for storing error messages
*/
void reader_set_highlight_function( void (*f)( wchar_t *, int *, int, array_list_t * ) );
*/
void reader_set_highlight_function( highlight_function_t );
/**
Specify function for testing if the command buffer contains syntax
@ -145,7 +154,7 @@ void reader_set_test_function( int (*f)( wchar_t * ) );
Specify string of shell commands to be run in order to generate the
prompt.
*/
void reader_set_prompt( wchar_t *prompt );
void reader_set_prompt( const wchar_t *prompt );
/**
Returns true if the shell is exiting, 0 otherwise.

View file

@ -392,7 +392,7 @@ void s_destroy( screen_t *s )
*/
static line_t *s_create_line()
{
line_t *current = malloc( sizeof( line_t ));
line_t *current = (line_t *)malloc( sizeof( line_t ));
al_init( &current->text );
al_init( &current->color );
return current;
@ -704,8 +704,8 @@ static void s_update( screen_t *scr, wchar_t *prompt )
for( j=start_pos; j<al_get_count( &o_line->text ); j++ )
{
wchar_t o = (wchar_t)(long)al_get( &o_line->text, j );
int o_c = (int)(long)al_get( &o_line->color, j );
wchar_t o = (wchar_t)(intptr_t)al_get( &o_line->text, j );
int o_c = (int)(intptr_t)al_get( &o_line->color, j );
if( !o )
@ -721,8 +721,8 @@ static void s_update( screen_t *scr, wchar_t *prompt )
}
else
{
wchar_t s = (wchar_t)(long)al_get( &s_line->text, j );
int s_c = (int)(long)al_get( &s_line->color, j );
wchar_t s = (wchar_t)(intptr_t)al_get( &s_line->text, j );
int s_c = (int)(intptr_t)al_get( &s_line->color, j );
if( o != s || o_c != s_c )
{
s_move( scr, &output, current_width, i );

View file

@ -87,7 +87,7 @@ static int check_size( tokenizer *tok, size_t len )
{
wchar_t *tmp;
tok->last_len = len +1;
tmp = realloc( tok->last, sizeof(wchar_t)*tok->last_len );
tmp = (wchar_t *)realloc( tok->last, sizeof(wchar_t)*tok->last_len );
if( tmp == 0 )
{
wperror( L"realloc" );

View file

@ -201,7 +201,7 @@ void hash_init2( hash_table_t *h,
sz--;
h->arr = malloc( sizeof(hash_struct_t)*sz );
h->arr = (hash_struct_t *)malloc( sizeof(hash_struct_t)*sz );
if( !h->arr )
{
oom_handler( h );
@ -286,7 +286,7 @@ static int hash_realloc( hash_table_t *h,
int i;
h->cache = -1;
h->arr = malloc( sizeof( hash_struct_t) * sz );
h->arr = (hash_struct_t *)malloc( sizeof( hash_struct_t) * sz );
if( h->arr == 0 )
{
h->arr = old_arr;
@ -642,7 +642,7 @@ int hash_str_cmp( void *a, void *b )
int hash_str_func( void *data )
{
int res = 0x67452301u;
const char *str = data;
const char *str = (const char *)data;
while( *str )
res = (18499*rotl5(res)) ^ *str++;
@ -773,7 +773,7 @@ void pq_destroy( priority_queue_t *q )
array_list_t *al_new()
{
array_list_t *res = malloc( sizeof( array_list_t ) );
array_list_t *res = (array_list_t *)malloc( sizeof( array_list_t ) );
if( !res )
{
@ -811,7 +811,7 @@ static int al_push_generic( array_list_t *l, anything_t o )
oom_handler( l );
return 0;
}
l->arr = tmp;
l->arr = (anything_t *)tmp;
l->size = new_size;
}
l->arr[l->pos++] = o;
@ -874,7 +874,7 @@ int al_insert( array_list_t *a, int pos, int count )
void *tmp = realloc( a->arr, sizeof( anything_t )*new_size );
if( tmp )
{
a->arr = tmp;
a->arr = (anything_t *)tmp;
}
else
{
@ -1005,7 +1005,7 @@ static anything_t al_pop_generic( array_list_t *l )
anything_t *old_arr = l->arr;
int old_size = l->size;
l->size = l->size/2;
l->arr = realloc( l->arr, sizeof(anything_t)*l->size );
l->arr = (anything_t *)realloc( l->arr, sizeof(anything_t)*l->size );
if( l->arr == 0 )
{
l->arr = old_arr;
@ -1188,7 +1188,7 @@ void sb_init( string_buffer_t * b)
string_buffer_t *sb_new()
{
string_buffer_t *res = malloc( sizeof( string_buffer_t ) );
string_buffer_t *res = (string_buffer_t *)malloc( sizeof( string_buffer_t ) );
if( !res )
{
@ -1265,7 +1265,7 @@ int sb_vprintf( string_buffer_t *buffer, const wchar_t *format, va_list va_orig
if( !buffer->length )
{
buffer->length = MIN_SIZE;
buffer->buff = malloc( MIN_SIZE );
buffer->buff = (char *)malloc( MIN_SIZE );
if( !buffer->buff )
{
oom_handler( buffer );
@ -1313,7 +1313,7 @@ int sb_vprintf( string_buffer_t *buffer, const wchar_t *format, va_list va_orig
break;
}
buffer->buff = realloc( buffer->buff, 2*buffer->length );
buffer->buff = (char *)realloc( buffer->buff, 2*buffer->length );
if( !buffer->buff )
{
@ -1407,7 +1407,7 @@ int b_append( buffer_t *b, const void *d, ssize_t len )
oom_handler( b );
return -1;
}
b->buff=d;
b->buff=(char *)d;
b->length = l;
}
memcpy( ((char*)b->buff)+b->used,

6
util.h
View file

@ -630,13 +630,13 @@ void sb_append_char( string_buffer_t *, wchar_t );
/**
Append all specified items to buffer.
*/
#define sb_append( sb,... ) sb_append_internal( sb, __VA_ARGS__, (void *)0 )
#define sb_append( sb,... ) sb_append_internal( sb, __VA_ARGS__, NULL )
/**
Append a null terminated list of strings to the buffer.
Example:
sb_append2( my_buff, L"foo", L"bar", (void *)0 );
sb_append2( my_buff, L"foo", L"bar", NULL );
Do not forget to cast the last 0 to (void *), or you might encounter errors on 64-bit platforms!
*/
@ -655,7 +655,7 @@ int sb_printf( string_buffer_t *buffer, const wchar_t *format, ... );
int sb_vprintf( string_buffer_t *buffer, const wchar_t *format, va_list va_orig );
/**
Destroy the buffer and free it's memory
Destroy the buffer and free its memory
*/
void sb_destroy( string_buffer_t * );

View file

@ -204,9 +204,7 @@ static char *posixly_correct;
char *getenv ();
static wchar_t *
my_index (str, chr)
const wchar_t *str;
int chr;
my_index (const wchar_t *str, int chr)
{
while (*str)
{
@ -250,8 +248,7 @@ static int last_nonopt;
the new indices of the non-options in ARGV after they are moved. */
static void
exchange (argv)
wchar_t **argv;
exchange (wchar_t **argv)
{
int bottom = first_nonopt;
int middle = last_nonopt;
@ -308,8 +305,7 @@ exchange (argv)
/* Initialize the internal data when the first call is made. */
static const wchar_t *
_wgetopt_initialize (optstring)
const wchar_t *optstring;
_wgetopt_initialize (const wchar_t *optstring)
{
/* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
@ -398,13 +394,7 @@ _wgetopt_initialize (optstring)
long-named options. */
int
_wgetopt_internal (argc, argv, optstring, longopts, longind, long_only)
int argc;
wchar_t *const *argv;
const wchar_t *optstring;
const struct woption *longopts;
int *longind;
int long_only;
_wgetopt_internal (int argc, wchar_t *const *argv, const wchar_t *optstring, const struct woption *longopts, int *longind, int long_only)
{
woptarg = NULL;
@ -696,10 +686,7 @@ int long_only;
}
int
wgetopt (argc, argv, optstring)
int argc;
wchar_t *const *argv;
const wchar_t *optstring;
wgetopt (int argc, wchar_t *const *argv, const wchar_t *optstring)
{
return _wgetopt_internal (argc, argv, optstring,
(const struct woption *) 0,
@ -708,23 +695,13 @@ wgetopt (argc, argv, optstring)
}
int
wgetopt_long (argc, argv, options, long_options, opt_index)
int argc;
wchar_t *const *argv;
const wchar_t *options;
const struct woption *long_options;
int *opt_index;
wgetopt_long (int argc, wchar_t *const *argv, const wchar_t *options, const struct woption *long_options, int *opt_index)
{
return _wgetopt_internal (argc, argv, options, long_options, opt_index, 0);
}
int
wgetopt_long_only (argc, argv, options, long_options, opt_index)
int argc;
wchar_t *const *argv;
const wchar_t *options;
const struct woption *long_options;
int *opt_index;
wgetopt_long_only (int argc, wchar_t *const *argv, const wchar_t *options, const struct woption *long_options, int *opt_index)
{
return _wgetopt_internal (argc, argv, options, long_options, opt_index, 1);
}

View file

@ -111,20 +111,20 @@ static hash_table_t *suffix_hash=0;
which is quite slow if the list is large. It might make sense to
use a hashtable for this.
*/
static void al_push_check( array_list_t *l, const wchar_t *new )
static void al_push_check( array_list_t *l, const wchar_t *newv )
{
int i;
for( i = 0; i < al_get_count(l); i++ )
{
if( !wcscmp( al_get(l, i), new ) )
if( !wcscmp( (const wchar_t *)al_get(l, i), newv ) )
{
free( (void *)new );
free( (void *)newv );
return;
}
}
al_push( l, new );
al_push( l, newv );
}
@ -369,7 +369,7 @@ static wchar_t *make_path( const wchar_t *base_dir, const wchar_t *name )
wchar_t *long_name;
int base_len = wcslen( base_dir );
if( !(long_name= malloc( sizeof(wchar_t)*(base_len+wcslen(name)+1) )))
if( !(long_name= (wchar_t *)malloc( sizeof(wchar_t)*(base_len+wcslen(name)+1) )))
{
DIE_MEM();
}
@ -464,7 +464,7 @@ static const wchar_t *complete_get_desc_suffix( const wchar_t *suff_orig )
if( !suffix_hash )
{
suffix_hash = malloc( sizeof( hash_table_t) );
suffix_hash = (hash_table_t *)malloc( sizeof( hash_table_t) );
if( !suffix_hash )
DIE_MEM();
hash_init( suffix_hash, &hash_wcs_func, &hash_wcs_cmp );
@ -729,7 +729,7 @@ static void wildcard_completion_allocate( array_list_t *list,
}
else
{
sb_append( sb, desc, L", ", (void *)0 );
sb_append( sb, desc, L", ", NULL );
sb_format_size( sb, sz );
}
@ -743,7 +743,7 @@ static void wildcard_completion_allocate( array_list_t *list,
expansion flags specified. flags can be a combination of
EXECUTABLES_ONLY and DIRECTORIES_ONLY.
*/
static int test_flags( wchar_t *filename,
static int test_flags( const wchar_t *filename,
int flags )
{
if( flags & DIRECTORIES_ONLY )
@ -788,7 +788,6 @@ static int wildcard_expand_internal( const wchar_t *wc,
wchar_t *wc_end;
/* Variables for traversing a directory */
struct wdirent *next;
DIR *dir;
/* The result returned */
@ -877,12 +876,13 @@ static int wildcard_expand_internal( const wchar_t *wc,
*/
if( flags & ACCEPT_INCOMPLETE )
{
while( (next=wreaddir(dir))!=0 )
wcstring next;
while(wreaddir(dir, next))
{
if( next->d_name[0] != L'.' )
if( next[0] != L'.' )
{
wchar_t *name = next->d_name;
wchar_t *long_name = make_path( base_dir, name );
const wchar_t *name = next.c_str();
const wchar_t *long_name = make_path( base_dir, name );
if( test_flags( long_name, flags ) )
{
@ -893,7 +893,7 @@ static int wildcard_expand_internal( const wchar_t *wc,
flags & EXECUTABLES_ONLY );
}
free( long_name );
free( (void *)long_name );
}
}
}
@ -908,9 +908,10 @@ static int wildcard_expand_internal( const wchar_t *wc,
/*
This is the last wildcard segment, and it is not empty. Match files/directories.
*/
while( (next=wreaddir(dir))!=0 )
wcstring next;
while(wreaddir(dir, next))
{
wchar_t *name = next->d_name;
const wchar_t *name = next.c_str();
if( flags & ACCEPT_INCOMPLETE )
{
@ -1023,7 +1024,7 @@ static int wildcard_expand_internal( const wchar_t *wc,
ln = MAX_FILE_LENGTH;
free( narrow_dir_string );
}
new_dir= malloc( sizeof(wchar_t)*(base_len+ln+2) );
new_dir= (wchar_t *)malloc( sizeof(wchar_t)*(base_len+ln+2) );
wc_str = wc_end?wcsndup(wc, wc_end-wc):wcsdup(wc);
@ -1034,9 +1035,10 @@ static int wildcard_expand_internal( const wchar_t *wc,
wcscpy( new_dir, base_dir );
while( (next=wreaddir(dir))!=0 )
wcstring next;
while (wreaddir(dir, next))
{
wchar_t *name = next->d_name;
const wchar_t *name = next.c_str();
/*
Test if the file/directory name matches the whole
@ -1179,7 +1181,7 @@ int wildcard_expand( const wchar_t *wc,
for( i=c; i<al_get_count( out ); i++ )
{
completion_t *c = al_get( out, i );
completion_t *c = (completion_t *)al_get( out, i );
if( c->flags & COMPLETE_NO_CASE )
{
@ -1200,3 +1202,20 @@ int wildcard_expand( const wchar_t *wc,
}
return res;
}
int wildcard_expand_string(const wcstring &wc, const wcstring &base_dir, int flags, std::vector<wcstring> &outputs )
{
array_list_t lst;
al_init(&lst);
int res = wildcard_expand(wc.c_str(), base_dir.c_str(), flags, &lst);
int i, max = al_get_count(&lst);
for (i=0; i < max; i++) {
wchar_t *tmp = (wchar_t *)al_get(&lst, i);
outputs.push_back(tmp);
free(tmp);
}
al_destroy(&lst);
return res;
}

View file

@ -13,8 +13,10 @@
#define FISH_WILDCARD_H
#include <wchar.h>
#include <vector>
#include "util.h"
#include "common.h"
/*
Use unencoded private-use keycodes for internal characters
@ -67,6 +69,8 @@ int wildcard_expand( const wchar_t *wc,
const wchar_t *base_dir,
int flags,
array_list_t *out );
int wildcard_expand_string(const wcstring &wc, const wcstring &base_dir, int flags, std::vector<wcstring> &out );
/**
Test whether the given wildcard matches the string

270
wutil.cpp
View file

@ -18,6 +18,7 @@
#include <stdarg.h>
#include <limits.h>
#include <libgen.h>
#include <string>
#if HAVE_LIBINTL_H
#include <libintl.h>
@ -31,6 +32,8 @@
#include "halloc.h"
#include "halloc_util.h"
typedef std::string cstring;
/**
Minimum length of the internal covnersion buffers
*/
@ -47,40 +50,6 @@
#endif
#endif
/**
Buffer for converting wide arguments to narrow arguments, used by
the \c wutil_wcs2str() function.
*/
static char *tmp=0;
/**
Buffer for converting narrow results to wide ones, used by the \c
wutil_str2wcs() function. Avoid usign this without thinking about
it, since subsequent calls will overwrite previous values.
*/
static wchar_t *tmp2;
/**
Length of the \c tmp buffer.
*/
static size_t tmp_len=0;
/**
Length of the \c tmp2 buffer
*/
static size_t tmp2_len;
/**
Counts the number of calls to the wutil wrapper functions
*/
static int wutil_calls = 0;
/**
Storage for the wreaddir function
*/
static struct wdirent my_wdirent;
/**
For wgettext: Number of string_buffer_t in the ring of buffers
*/
@ -118,84 +87,21 @@ void wutil_init()
void wutil_destroy()
{
free( tmp );
free( tmp2 );
tmp=0;
tmp_len=0;
debug( 3, L"wutil functions called %d times", wutil_calls );
}
/**
Convert the specified wide aharacter string to a narrow character
string. This function uses an internal temporary buffer for storing
the result so subsequent results will overwrite previous results.
*/
static char *wutil_wcs2str( const wchar_t *in )
{
size_t new_sz;
wutil_calls++;
new_sz =MAX_UTF8_BYTES*wcslen(in)+1;
if( tmp_len < new_sz )
{
new_sz = maxi( new_sz, TMP_LEN_MIN );
tmp = realloc( tmp, new_sz );
if( !tmp )
{
DIE_MEM();
}
tmp_len = new_sz;
}
return wcs2str_internal( in, tmp );
}
/**
Convert the specified wide character string to a narrow character
string. This function uses an internal temporary buffer for storing
the result so subsequent results will overwrite previous results.
*/
static wchar_t *wutil_str2wcs( const char *in )
{
size_t new_sz;
wutil_calls++;
new_sz = sizeof(wchar_t)*(strlen(in)+1);
if( tmp2_len < new_sz )
{
new_sz = maxi( new_sz, TMP_LEN_MIN );
tmp2 = realloc( tmp2, new_sz );
if( !tmp2 )
{
DIE_MEM();
}
tmp2_len = new_sz;
}
return str2wcs_internal( in, tmp2 );
}
struct wdirent *wreaddir(DIR *dir )
std::wstring *wreaddir(DIR *dir, std::wstring &outPath)
{
struct dirent *d = readdir( dir );
if( !d )
return 0;
my_wdirent.d_name = wutil_str2wcs( d->d_name );
return &my_wdirent;
if ( !d ) return 0;
outPath = str2wcstring(d->d_name);
return &outPath;
}
wchar_t *wgetcwd( wchar_t *buff, size_t sz )
{
char *buffc = malloc( sz*MAX_UTF8_BYTES);
char *buffc = (char *)malloc( sz*MAX_UTF8_BYTES);
char *res;
wchar_t *ret = 0;
@ -221,120 +127,70 @@ wchar_t *wgetcwd( wchar_t *buff, size_t sz )
int wchdir( const wchar_t * dir )
{
char *tmp = wutil_wcs2str(dir);
return chdir( tmp );
cstring tmp = wcs2string(dir);
return chdir( tmp.c_str() );
}
FILE *wfopen(const wchar_t *path, const char *mode)
{
char *tmp =wutil_wcs2str(path);
FILE *res=0;
if( tmp )
{
res = fopen(tmp, mode);
}
return res;
cstring tmp = wcs2string(path);
return fopen(tmp.c_str(), mode);
}
FILE *wfreopen(const wchar_t *path, const char *mode, FILE *stream)
{
char *tmp =wutil_wcs2str(path);
FILE *res=0;
if( tmp )
{
res = freopen(tmp, mode, stream);
}
return res;
cstring tmp = wcs2string(path);
return freopen(tmp.c_str(), mode, stream);
}
int wopen(const wchar_t *pathname, int flags, ...)
{
char *tmp =wutil_wcs2str(pathname);
cstring tmp = wcs2string(pathname);
int res=-1;
va_list argp;
if( tmp )
{
if( ! (flags & O_CREAT) )
{
res = open(tmp, flags);
res = open(tmp.c_str(), flags);
}
else
{
va_start( argp, flags );
res = open(tmp, flags, va_arg(argp, int) );
res = open(tmp.c_str(), flags, va_arg(argp, int) );
va_end( argp );
}
}
return res;
}
int wcreat(const wchar_t *pathname, mode_t mode)
{
char *tmp =wutil_wcs2str(pathname);
int res = -1;
if( tmp )
{
res= creat(tmp, mode);
}
return res;
cstring tmp = wcs2string(pathname);
return creat(tmp.c_str(), mode);
}
DIR *wopendir(const wchar_t *name)
{
char *tmp =wutil_wcs2str(name);
DIR *res = 0;
if( tmp )
{
res = opendir(tmp);
}
return res;
cstring tmp = wcs2string(name);
return opendir(tmp.c_str());
}
int wstat(const wchar_t *file_name, struct stat *buf)
{
char *tmp =wutil_wcs2str(file_name);
int res = -1;
if( tmp )
{
res = stat(tmp, buf);
}
return res;
cstring tmp = wcs2string(file_name);
return stat(tmp.c_str(), buf);
}
int lwstat(const wchar_t *file_name, struct stat *buf)
{
char *tmp =wutil_wcs2str(file_name);
int res = -1;
if( tmp )
{
res = lstat(tmp, buf);
}
return res;
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
cstring tmp = wcs2string(file_name);
return lstat(tmp.c_str(), buf);
}
int waccess(const wchar_t *file_name, int mode)
{
char *tmp =wutil_wcs2str(file_name);
int res = -1;
if( tmp )
{
res= access(tmp, mode);
}
return res;
cstring tmp = wcs2string(file_name);
return access(tmp.c_str(), mode);
}
void wperror(const wchar_t *s)
@ -351,8 +207,8 @@ void wperror(const wchar_t *s)
wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path)
{
char *tmp = wutil_wcs2str(pathname);
char *narrow_res = realpath( tmp, 0 );
cstring tmp = wcs2string(pathname);
char *narrow_res = realpath( tmp.c_str(), 0 );
wchar_t *res;
if( !narrow_res )
@ -379,9 +235,9 @@ wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path)
wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path)
{
char *tmp = wutil_wcs2str(pathname);
cstring tmp = wcs2string(pathname);
char narrow_buff[PATH_MAX];
char *narrow_res = realpath( tmp, narrow_buff );
char *narrow_res = realpath( tmp.c_str(), narrow_buff );
wchar_t *res;
if( !narrow_res )
@ -404,43 +260,24 @@ wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path)
#endif
wchar_t *wdirname( wchar_t *path )
wcstring wdirname( const wcstring &path )
{
static string_buffer_t *sb = 0;
if( sb )
sb_clear(sb);
else
sb = sb_halloc( global_context );
char *tmp =wutil_wcs2str(path);
char *tmp = wcs2str(path.c_str());
char *narrow_res = dirname( tmp );
if( !narrow_res )
return 0;
sb_printf( sb, L"%s", narrow_res );
wcscpy( path, (wchar_t *)sb->buff );
return path;
wcstring result = format_string(L"%s", narrow_res);
free(tmp);
return result;
}
wchar_t *wbasename( const wchar_t *path )
wcstring wbasename( const wcstring &path )
{
static string_buffer_t *sb = 0;
if( sb )
sb_clear(sb);
else
sb = sb_halloc( global_context );
char *tmp =wutil_wcs2str(path);
char *tmp = wcs2str(path.c_str());
char *narrow_res = basename( tmp );
if( !narrow_res )
return 0;
sb_printf( sb, L"%s", narrow_res );
return (wchar_t *)sb->buff;
wcstring result = format_string(L"%s", narrow_res);
free(tmp);
return result;
}
/**
For wgettext: Internal shutdown function. Automatically called on shutdown if the library has been initialized.
*/
@ -489,7 +326,7 @@ static char *wgettext_wcs2str( const wchar_t *in )
size_t len = MAX_UTF8_BYTES*wcslen(in)+1;
if( len > wcs2str_buff_count )
{
wcs2str_buff = realloc( wcs2str_buff, len );
wcs2str_buff = (char *)realloc( wcs2str_buff, len );
if( !wcs2str_buff )
{
DIE_MEM();
@ -522,8 +359,8 @@ const wchar_t *wgettext( const wchar_t *in )
wchar_t *wgetenv( const wchar_t *name )
{
char *name_narrow =wutil_wcs2str(name);
char *res_narrow = getenv( name_narrow );
cstring name_narrow = wcs2string(name);
char *res_narrow = getenv( name_narrow.c_str() );
static string_buffer_t *out = 0;
if( !res_narrow )
@ -546,18 +383,13 @@ wchar_t *wgetenv( const wchar_t *name )
int wmkdir( const wchar_t *name, int mode )
{
char *name_narrow =wutil_wcs2str(name);
return mkdir( name_narrow, mode );
cstring name_narrow = wcs2string(name);
return mkdir( name_narrow.c_str(), mode );
}
int wrename( const wchar_t *old, const wchar_t *new )
int wrename( const wchar_t *old, const wchar_t *newv )
{
char *old_narrow =wutil_wcs2str(old);
char *new_narrow =wcs2str(new);
int res;
res = rename( old_narrow, new_narrow );
free( new_narrow );
return res;
cstring old_narrow = wcs2string(old);
cstring new_narrow =wcs2string(newv);
return rename( old_narrow.c_str(), new_narrow.c_str() );
}

14
wutil.h
View file

@ -14,6 +14,9 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <stdarg.h>
#include <string>
/**
Wide version of the dirent data structure
@ -24,8 +27,7 @@ struct wdirent
The name of the current directory
*/
wchar_t *d_name;
}
;
};
/**
@ -106,17 +108,17 @@ wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path);
/**
Wide character version of readdir()
*/
struct wdirent *wreaddir(DIR *dir );
std::wstring *wreaddir(DIR *dir, std::wstring &outPath);
/**
Wide character version of dirname()
*/
wchar_t *wdirname( wchar_t *path );
std::wstring wdirname( const std::wstring &path);
/**
Wide character version of basename()
*/
wchar_t *wbasename( const wchar_t *path );
std::wstring wbasename( const std::wstring &path);
/**
Wide character wrapper around the gettext function. For historic
@ -141,6 +143,6 @@ int wmkdir( const wchar_t *dir, int mode );
/**
Wide character version of rename
*/
int wrename( const wchar_t *old, const wchar_t *new );
int wrename( const wchar_t *oldName, const wchar_t *newName );
#endif

View file

@ -93,7 +93,7 @@ xdg_dir_time_list_new (void)
{
XdgDirTimeList *retval;
retval = calloc (1, sizeof (XdgDirTimeList));
retval = (XdgDirTimeList *)calloc (1, sizeof (XdgDirTimeList));
retval->checked = XDG_CHECKED_UNCHECKED;
return retval;
@ -122,7 +122,7 @@ xdg_mime_init_from_directory (const char *directory)
assert (directory != NULL);
file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
file_name = (char *)malloc (strlen (directory) + strlen ("/mime/globs") + 1);
strcpy (file_name, directory); strcat (file_name, "/mime/globs");
if (stat (file_name, &st) == 0)
{
@ -139,7 +139,7 @@ xdg_mime_init_from_directory (const char *directory)
free (file_name);
}
file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
file_name = (char *)malloc (strlen (directory) + strlen ("/mime/magic") + 1);
strcpy (file_name, directory); strcat (file_name, "/mime/magic");
if (stat (file_name, &st) == 0)
{
@ -156,12 +156,12 @@ xdg_mime_init_from_directory (const char *directory)
free (file_name);
}
file_name = malloc (strlen (directory) + strlen ("/mime/aliases") + 1);
file_name = (char *)malloc (strlen (directory) + strlen ("/mime/aliases") + 1);
strcpy (file_name, directory); strcat (file_name, "/mime/aliases");
_xdg_mime_alias_read_from_file (alias_list, file_name);
free (file_name);
file_name = malloc (strlen (directory) + strlen ("/mime/subclasses") + 1);
file_name = (char *)malloc (strlen (directory) + strlen ("/mime/subclasses") + 1);
strcpy (file_name, directory); strcat (file_name, "/mime/subclasses");
_xdg_mime_parent_read_from_file (parent_list, file_name);
free (file_name);
@ -194,7 +194,7 @@ xdg_run_command_on_dirs (XdgDirectoryFunc func,
char *guessed_xdg_home;
int stop_processing;
guessed_xdg_home = malloc (strlen (home) + strlen ("/.local/share/") + 1);
guessed_xdg_home = (char *)malloc (strlen (home) + strlen ("/.local/share/") + 1);
strcpy (guessed_xdg_home, home);
strcat (guessed_xdg_home, "/.local/share/");
stop_processing = (func) (guessed_xdg_home, user_data);
@ -232,7 +232,7 @@ xdg_run_command_on_dirs (XdgDirectoryFunc func,
len = end_ptr - ptr;
else
len = end_ptr - ptr + 1;
dir = malloc (len + 1);
dir = (char *)malloc (len + 1);
strncpy (dir, ptr, len);
dir[len] = '\0';
stop_processing = (func) (dir, user_data);
@ -290,7 +290,7 @@ xdg_check_dir (const char *directory,
assert (directory != NULL);
/* Check the globs file */
file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
file_name = (char *)malloc (strlen (directory) + strlen ("/mime/globs") + 1);
strcpy (file_name, directory); strcat (file_name, "/mime/globs");
invalid = xdg_check_file (file_name);
free (file_name);
@ -301,7 +301,7 @@ xdg_check_dir (const char *directory,
}
/* Check the magic file */
file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
file_name = (char *)malloc (strlen (directory) + strlen ("/mime/magic") + 1);
strcpy (file_name, directory); strcat (file_name, "/mime/magic");
invalid = xdg_check_file (file_name);
free (file_name);
@ -437,7 +437,7 @@ xdg_mime_get_mime_type_for_file (const char *file_name)
* be large and need getting from a stream instead of just reading it all
* in. */
max_extent = _xdg_mime_magic_get_buffer_extents (global_magic);
data = malloc (max_extent);
data = (unsigned char *)malloc (max_extent);
if (data == NULL)
return XDG_MIME_TYPE_UNKNOWN;
@ -674,7 +674,7 @@ xdg_mime_register_reload_callback (XdgMimeCallback callback,
static int callback_id = 1;
/* Make a new list element */
list_el = calloc (1, sizeof (XdgCallbackList));
list_el = (XdgCallbackList *)calloc (1, sizeof (XdgCallbackList));
list_el->callback_id = callback_id;
list_el->callback = callback;
list_el->data = data;

View file

@ -64,7 +64,7 @@ _xdg_mime_alias_list_new (void)
{
XdgAliasList *list;
list = malloc (sizeof (XdgAliasList));
list = (XdgAliasList *)malloc (sizeof (XdgAliasList));
list->aliases = NULL;
list->n_aliases = 0;
@ -107,7 +107,7 @@ _xdg_mime_alias_list_lookup (XdgAliasList *list,
key.alias = (char *)alias;
key.mime_type = 0;
entry = bsearch (&key, list->aliases, list->n_aliases,
entry = (XdgAlias *)bsearch (&key, list->aliases, list->n_aliases,
sizeof (XdgAlias), alias_entry_cmp);
if (entry)
return entry->mime_type;
@ -132,7 +132,7 @@ _xdg_mime_alias_read_from_file (XdgAliasList *list,
/* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars.
* Blah */
alloc = list->n_aliases + 16;
list->aliases = realloc (list->aliases, alloc * sizeof (XdgAlias));
list->aliases = (XdgAlias *)realloc (list->aliases, alloc * sizeof (XdgAlias));
while (fgets (line, 255, file) != NULL)
{
char *sep;
@ -147,14 +147,14 @@ _xdg_mime_alias_read_from_file (XdgAliasList *list,
if (list->n_aliases == alloc)
{
alloc <<= 1;
list->aliases = realloc (list->aliases,
list->aliases = (XdgAlias *)realloc (list->aliases,
alloc * sizeof (XdgAlias));
}
list->aliases[list->n_aliases].alias = strdup (line);
list->aliases[list->n_aliases].mime_type = strdup (sep);
list->n_aliases++;
}
list->aliases = realloc (list->aliases,
list->aliases = (XdgAlias *)realloc (list->aliases,
list->n_aliases * sizeof (XdgAlias));
fclose (file);

View file

@ -77,7 +77,7 @@ _xdg_glob_list_new (void)
{
XdgGlobList *new_element;
new_element = calloc (1, sizeof (XdgGlobList));
new_element = (XdgGlobList *)calloc (1, sizeof (XdgGlobList));
return new_element;
}
@ -113,7 +113,7 @@ _xdg_glob_list_append (XdgGlobList *glob_list,
XdgGlobList *tmp_element;
new_element = _xdg_glob_list_new ();
new_element->data = data;
new_element->data = (const char *)data;
new_element->mime_type = mime_type;
if (glob_list == NULL)
return new_element;
@ -152,7 +152,7 @@ _xdg_glob_hash_node_new (void)
{
XdgGlobHashNode *glob_hash_node;
glob_hash_node = calloc (1, sizeof (XdgGlobHashNode));
glob_hash_node = (XdgGlobHashNode *)calloc (1, sizeof (XdgGlobHashNode));
return glob_hash_node;
}
@ -328,7 +328,7 @@ _xdg_glob_hash_new (void)
{
XdgGlobHash *glob_hash;
glob_hash = calloc (1, sizeof (XdgGlobHash));
glob_hash = (XdgGlobHash *)calloc (1, sizeof (XdgGlobHash));
return glob_hash;
}

View file

@ -91,7 +91,7 @@ struct XdgMimeMagic
static XdgMimeMagicMatch *
_xdg_mime_magic_match_new (void)
{
return calloc (1, sizeof (XdgMimeMagicMatch));
return (XdgMimeMagicMatch *)calloc (1, sizeof (XdgMimeMagicMatch));
}
@ -100,7 +100,7 @@ _xdg_mime_magic_matchlet_new (void)
{
XdgMimeMagicMatchlet *matchlet;
matchlet = malloc (sizeof (XdgMimeMagicMatchlet));
matchlet = (XdgMimeMagicMatchlet *)malloc (sizeof (XdgMimeMagicMatchlet));
matchlet->indent = 0;
matchlet->offset = 0;
@ -166,7 +166,7 @@ _xdg_mime_magic_read_to_newline (FILE *magic_file,
len = 128;
pos = 0;
retval = malloc (len);
retval = (char *)malloc (len);
*end_of_file = FALSE;
while (TRUE)
@ -183,7 +183,7 @@ _xdg_mime_magic_read_to_newline (FILE *magic_file,
if (pos % 128 == 127)
{
len = len + 128;
retval = realloc (retval, len);
retval = (char *)realloc (retval, len);
}
}
@ -393,7 +393,7 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_file,
}
matchlet->value_length = matchlet->value_length + (c & 0xFF);
matchlet->value = malloc (matchlet->value_length);
matchlet->value = (unsigned char *)malloc (matchlet->value_length);
/* OOM */
if (matchlet->value == NULL)
@ -414,7 +414,7 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_file,
c = getc_unlocked (magic_file);
if (c == '&')
{
matchlet->mask = malloc (matchlet->value_length);
matchlet->mask = (unsigned char *)malloc (matchlet->value_length);
/* OOM */
if (matchlet->mask == NULL)
{
@ -633,7 +633,7 @@ _xdg_mime_magic_insert_match (XdgMimeMagic *mime_magic,
XdgMimeMagic *
_xdg_mime_magic_new (void)
{
return calloc (1, sizeof (XdgMimeMagic));
return (XdgMimeMagic *)calloc (1, sizeof (XdgMimeMagic));
}
void

View file

@ -65,7 +65,7 @@ _xdg_mime_parent_list_new (void)
{
XdgParentList *list;
list = malloc (sizeof (XdgParentList));
list = (XdgParentList *)malloc (sizeof (XdgParentList));
list->parents = NULL;
list->n_mimes = 0;
@ -112,7 +112,7 @@ _xdg_mime_parent_list_lookup (XdgParentList *list,
key.mime = (char *)mime;
key.parents = NULL;
entry = bsearch (&key, list->parents, list->n_mimes,
entry = (XdgMimeParents *)bsearch (&key, list->parents, list->n_mimes,
sizeof (XdgMimeParents), &parent_entry_cmp);
if (entry)
return (const char **)entry->parents;
@ -138,7 +138,7 @@ _xdg_mime_parent_read_from_file (XdgParentList *list,
/* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars.
* Blah */
alloc = list->n_mimes + 16;
list->parents = realloc (list->parents, alloc * sizeof (XdgMimeParents));
list->parents = (XdgMimeParents *)realloc (list->parents, alloc * sizeof (XdgMimeParents));
while (fgets (line, 255, file) != NULL)
{
char *sep;
@ -165,7 +165,7 @@ _xdg_mime_parent_read_from_file (XdgParentList *list,
if (list->n_mimes == alloc)
{
alloc <<= 1;
list->parents = realloc (list->parents,
list->parents = (XdgMimeParents *)realloc (list->parents,
alloc * sizeof (XdgMimeParents));
}
list->parents[list->n_mimes].mime = strdup (line);
@ -177,19 +177,19 @@ _xdg_mime_parent_read_from_file (XdgParentList *list,
if (!entry->parents)
{
entry->n_parents = 1;
entry->parents = malloc ((entry->n_parents + 1) * sizeof (char *));
entry->parents = (char **)malloc ((entry->n_parents + 1) * sizeof (char *));
}
else
{
entry->n_parents += 1;
entry->parents = realloc (entry->parents,
entry->parents = (char **)realloc (entry->parents,
(entry->n_parents + 2) * sizeof (char *));
}
entry->parents[entry->n_parents - 1] = strdup (sep);
entry->parents[entry->n_parents] = NULL;
}
list->parents = realloc (list->parents,
list->parents = (XdgMimeParents *)realloc (list->parents,
list->n_mimes * sizeof (XdgMimeParents));
fclose (file);