int vs_write_cpp() { const char* str; int i, b; VsPkgData* data = (VsPkgData*)prj_get_data(); /* Open the file and write the header */ if (!io_openfile(path_join(prj_get_pkgpath(), prj_get_pkgname(), "vcproj"))) return 0; prj_select_config(0); io_print("<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n"); tag_open("VisualStudioProject"); tag_attr("ProjectType=\"Visual C++\""); switch (version) { case VS2002: str = "7.00"; break; case VS2003: str = "7.10"; break; case VS2005: str = "8.00"; break; case VS2008: str = "9.00"; break; } tag_attr("Version=\"%s\"", str); tag_attr("Name=\"%s\"", prj_get_pkgname()); tag_attr("ProjectGUID=\"{%s}\"", data->projGuid); if (version >= VS2005) tag_attr("RootNamespace=\"%s\"", prj_get_pkgname()); tag_attr("Keyword=\"%s\"", prj_has_flag("managed") ? "ManagedCProj" : "Win32Proj"); tag_open("Platforms"); tag_open("Platform"); tag_attr("Name=\"Win32\""); tag_close("Platform", 0); tag_close("Platforms", 1); if (version >= VS2005) { tag_open("ToolFiles"); tag_close("ToolFiles", 1); } /* Write configurations */ tag_open("Configurations"); for (i = 0; i < prj_get_numconfigs(); ++i) { int optimization, debug, runtime, symbols, configTypeId; const char* pchHeader = prj_get_pch_header(); prj_select_config(i); if (prj_is_kind("winexe") || prj_is_kind("exe") || prj_is_kind("cxxtestgen") || prj_is_kind("run")) { configTypeId = 1; } else if (prj_is_kind("dll")) { configTypeId = 2; } else if (prj_is_kind("lib")) { configTypeId = 4; } else if (prj_is_kind("aspnet")) { puts("** Error: C++ ASP.NET projects are not supported"); return 0; } else { printf("** Error: unknown package kind '%s'\n", prj_get_kind()); return 0; } if (prj_has_flag("optimize-speed")) optimization = 2; else if (prj_has_flag("optimize-size")) optimization = 1; else if (prj_has_flag("optimize")) optimization = 3; else optimization = 0; debug = (optimization ==0); if (prj_has_flag("static-runtime")) runtime = (debug) ? 1 : 0; else runtime = (debug) ? 3 : 2; if (prj_has_flag("no-symbols")) symbols = 0; else symbols = (prj_has_flag("managed") || prj_has_flag("no-edit-and-continue")) ? 3 : 4; tag_open("Configuration"); tag_attr("Name=\"%s|Win32\"", prj_get_cfgname()); tag_attr("OutputDirectory=\"%s\"", prj_get_outdir()); tag_attr("IntermediateDirectory=\"%s\"", prj_get_objdir()); tag_attr("ConfigurationType=\"%d\"", configTypeId); tag_attr("CharacterSet=\"%d\"", prj_has_flag("unicode") ? 1 : 2); if (prj_has_flag("managed")) tag_attr("ManagedExtensions=\"%s\"", S_TRUE); /* Write out tool blocks */ for (b = 0; blocks[version][b] != BlocksEnd; ++b) { tag_open("Tool"); switch (blocks[version][b]) { case VCPreBuildEventTool: tag_attr("Name=\"VCPreBuildEventTool\""); break; case VCCustomBuildTool: tag_attr("Name=\"VCCustomBuildTool\""); if (prj_is_kind("run")) { tag_attr("Description=\"Running CxxTest Test Suite\""); tag_attr_open("CommandLine"); print_list(prj_get_links(), "", "", " ", vs_filter_links); print_list(prj_get_buildoptions(), " ", "", "", NULL); tag_attr_close(); // This so that we're always run (and never "up-to-date") tag_attr("Outputs=\".\\dummy.file.thats.never.created\""); } else if (prj_is_kind("cxxtestgen")) { char *rootfile = strdup(prj_get_cxxtest_rootfile()); char *ctpath = strdup(path_translate(prj_get_cxxtestpath(), "windows")); char *options = strdup(prj_get_cxxtest_rootoptions()); tag_attr("Description=\"Generating test_root.cpp\""); tag_attr("CommandLine=\"%s%s --root %s -o "%s"\"", endsWith(prj_get_cxxtestpath(), ".pl")?"perl ":"", ctpath, options, rootfile); tag_attr("Outputs=\"%s\"", rootfile); free(options); free(ctpath); free(rootfile); } break; case VCXMLDataGeneratorTool: tag_attr("Name=\"VCXMLDataGeneratorTool\""); break; case VCManagedWrapperGeneratorTool: tag_attr("Name=\"VCManagedWrapperGeneratorTool\""); break; case VCAuxiliaryManagedWrapperGeneratorTool: tag_attr("Name=\"VCAuxiliaryManagedWrapperGeneratorTool\""); break; case VCWebServiceProxyGeneratorTool: tag_attr("Name=\"VCWebServiceProxyGeneratorTool\""); break; case VCMIDLTool: tag_attr("Name=\"VCMIDLTool\""); break; case VCManagedResourceCompilerTool: tag_attr("Name=\"VCManagedResourceCompilerTool\""); break; case VCResourceCompilerTool: tag_attr("Name=\"VCResourceCompilerTool\""); if (prj_get_numincpaths() > 0) { tag_attr_open("AdditionalIncludeDirectories"); print_list(prj_get_incpaths(), "", "", ";", NULL); tag_attr_close(); } break; case VCPreLinkEventTool: tag_attr("Name=\"VCPreLinkEventTool\""); break; case VCALinkTool: tag_attr("Name=\"VCALinkTool\""); break; case VCManifestTool: tag_attr("Name=\"VCManifestTool\""); break; case VCXDCMakeTool: tag_attr("Name=\"VCXDCMakeTool\""); break; case VCBscMakeTool: tag_attr("Name=\"VCBscMakeTool\""); break; case VCFxCopTool: tag_attr("Name=\"VCFxCopTool\""); break; case VCAppVerifierTool: tag_attr("Name=\"VCAppVerifierTool\""); break; case VCWebDeploymentTool: tag_attr("Name=\"VCWebDeploymentTool\""); break; case VCPostBuildEventTool: tag_attr("Name=\"VCPostBuildEventTool\""); break; case VCCLCompilerTool: tag_attr("Name=\"VCCLCompilerTool\""); if (prj_get_numbuildoptions() > 0) { tag_attr_open("AdditionalOptions"); print_list(prj_get_buildoptions(), "", "", " ", NULL); tag_attr_close(); } tag_attr("Optimization=\"%d\"", optimization); if (prj_has_flag("no-frame-pointer")) tag_attr("OmitFramePointers=\"%s\"", S_TRUE); if (prj_get_numincpaths() > 0) { tag_attr_open("AdditionalIncludeDirectories"); print_list(prj_get_incpaths(), "", "", ";", NULL); tag_attr_close(); } if (prj_has_flag("managed")) tag_attr("AdditionalUsingDirectories=\"%s\"", prj_get_bindir()); if (prj_get_numdefines() > 0) { tag_attr_open("PreprocessorDefinitions"); print_list(prj_get_defines(), "", "", ";", NULL); tag_attr_close(); } if (debug && !prj_has_flag("managed")) tag_attr("MinimalRebuild=\"%s\"", S_TRUE); if (prj_has_flag("no-exceptions")) tag_attr("ExceptionHandling=\"%s\"", S_FALSE); if (debug && !prj_has_flag("managed")) tag_attr("BasicRuntimeChecks=\"3\""); if (!debug) tag_attr("StringPooling=\"%s\"", S_TRUE); tag_attr("RuntimeLibrary=\"%d\"", runtime); tag_attr("EnableFunctionLevelLinking=\"%s\"", S_TRUE); if (version < VS2005 && !prj_has_flag("no-rtti")) tag_attr("RuntimeTypeInfo=\"%s\"", S_TRUE); if (version >= VS2005 && prj_has_flag("no-rtti")) tag_attr("RuntimeTypeInfo=\"%s\"", S_FALSE); if (version < VS2005 && prj_has_flag("native-wchar_t")) tag_attr("TreatWChar_tAsBuiltInType=\"%s\"", S_TRUE); if (version >= VS2005 && prj_has_flag("no-native-wchar_t")) tag_attr("TreatWChar_tAsBuiltInType=\"%s\"", S_FALSE); if (pchHeader) { tag_attr("UsePrecompiledHeader=\"%d\"", version < VS2005 ? 3 : 2); tag_attr("PrecompiledHeaderThrough=\"%s\"", pchHeader); } else tag_attr("UsePrecompiledHeader=\"%d\"", version < VS2005 ? 2 : 0); tag_attr("WarningLevel=\"%d\"", prj_has_flag("extra-warnings") ? 4 : 3); if (prj_has_flag("fatal-warnings")) tag_attr("WarnAsError=\"%s\"", S_TRUE); if (version < VS2008 && !prj_has_flag("managed")) tag_attr("Detect64BitPortabilityProblems=\"%s\"", prj_has_flag("no-64bit-checks") ? S_FALSE : S_TRUE); tag_attr("DebugInformationFormat=\"%d\"", symbols); break; case VCLinkerTool: if (!prj_is_kind("lib")) { tag_attr("Name=\"VCLinkerTool\""); if (prj_has_flag("no-import-lib")) tag_attr("IgnoreImportLibrary=\"%s\"", S_TRUE); if (prj_has_flag("use-library-dep-inputs") && version >= VS2005) tag_attr("UseLibraryDependencyInputs=\"%s\"", S_TRUE); if (prj_get_numlinkoptions() > 0) { tag_attr_open("AdditionalOptions"); print_list(prj_get_linkoptions(), " ", "", "", NULL); tag_attr_close(); } if (prj_get_numlinks() > 0) { tag_attr_open("AdditionalDependencies"); print_list(prj_get_links(), "", ".lib", " ", vs_filter_links); tag_attr_close(); } tag_attr("OutputFile=\"$(OutDir)/%s\"", path_getname(prj_get_target())); tag_attr("LinkIncremental=\"%d\"", debug ? 2 : 1); tag_attr_open("AdditionalLibraryDirectories"); io_print(prj_get_libdir()); print_list(prj_get_libpaths(), ";", "", "", NULL); tag_attr_close(); /* Look for a .def file for DLLs */ if (prj_find_filetype(".def") != NULL) tag_attr("ModuleDefinitionFile=\"%s\"", prj_find_filetype(".def")); if (prj_has_flag("no-manifest")) tag_attr("GenerateManifest=\"%s\"", S_FALSE); tag_attr("GenerateDebugInformation=\"%s\"", symbols ? S_TRUE : S_FALSE); if (symbols) tag_attr("ProgramDatabaseFile=\"$(OutDir)/%s.pdb\"", path_getbasename(prj_get_target())); tag_attr("SubSystem=\"%d\"", prj_is_kind("exe") ? 1 : 2); if (!debug) tag_attr("OptimizeReferences=\"2\""); if (!debug) tag_attr("EnableCOMDATFolding=\"2\""); if ((prj_is_kind("exe") || prj_is_kind("winexe")) && !prj_has_flag("no-main")) { tag_attr("EntryPointSymbol=\"mainCRTStartup\""); } else if (prj_is_kind("dll")) { tag_attr_open("ImportLibrary"); if (prj_has_flag("no-import-lib")) io_print(prj_get_objdir()); else io_print(prj_get_libdir()); io_print("/%s.lib", path_getbasename(prj_get_target())); tag_attr_close(); } tag_attr("TargetMachine=\"1\""); } else { tag_attr("Name=\"VCLibrarianTool\""); tag_attr("OutputFile=\"$(OutDir)/%s.lib\"", path_getbasename(prj_get_target())); } break; } tag_close("", 0); } tag_close("Configuration", 1); } tag_close("Configurations", 1); if (version > VS2002) { tag_open("References"); tag_close("References", 1); } tag_open("Files"); print_source_tree("", vs_list_files); /*if (prj_is_kind("cxxtestgen")) { char *rootfile = strdup(prj_get_cxxtest_rootfile()); char *ctpath = strdup(path_translate(prj_get_cxxtestpath(), "windows")); int i; tag_open("File"); tag_attr_open("RelativePath"); if (rootfile[0] != '.') io_print(".\\"); io_print(rootfile); tag_attr_close(); for (i = 0; i < prj_get_numconfigs(); ++i) { char *options; prj_select_config(i); options = strdup(prj_get_cxxtest_rootoptions()); tag_open("FileConfiguration"); tag_attr("Name=\"%s|Win32\"", prj_get_cfgname()); tag_open("Tool"); tag_attr("Name=\"VCCustomBuildTool\""); tag_attr("Description=\"Generating test_root.cpp\""); tag_attr("CommandLine=\"%s%s --root %s -o "%s"\"", endsWith(prj_get_cxxtestpath(), ".pl")?"perl ":"", ctpath, options, rootfile); tag_attr("Outputs=\"%s\"", rootfile); tag_close("Tool", 0); tag_close("FileConfiguration", 1); free(options); } tag_close("File", 1); free(ctpath); free(rootfile); }*/ tag_close("Files", 1); tag_open("Globals"); tag_close("Globals", 1); tag_close("VisualStudioProject", 1); io_closefile(); return 1; }
void print_about(const int debuglvl) { int max_height = 0, max_width = 0, height = 0, width = 0, startx = 0, starty = 0; struct vrmr_list about_list; /* top menu */ char *key_choices[] = { "F10" }; int key_choices_n = 1; char *cmd_choices[] = { gettext("back") }; int cmd_choices_n = 1; char about_version_string[sizeof(version_string)]; /* create the about version string */ snprintf(about_version_string, sizeof(about_version_string), "Version: %s\n", version_string); /* get screensize */ getmaxyx(stdscr, max_height, max_width); width = 72; height = max_height - 8; startx = (max_width - width) / 2; starty = 4; vrmr_list_setup(debuglvl, &about_list, free_helpword); (void)read_helpline(debuglvl, &about_list, "Vuurmuur_conf\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "=============\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, about_version_string); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Copyright 2003-2007 (c) Victor Julien <victor(at)vuurmuur(dot)org>.\n"); (void)read_helpline(debuglvl, &about_list, "This program is distributed under the terms of the GPL.\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Support\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "=======\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Website: http://www.vuurmuur.org/\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Mailinglist: http://sourceforge.net/mail/?group_id=114382\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Forum: http://sourceforge.net/forum/?group_id=114382\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "IRC: irc://irc.freenode.net/vuurmuur\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Thanks to\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "=========\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Philippe Baumgart (documentation).\n"); (void)read_helpline(debuglvl, &about_list, "Michiel Bodewes (website development).\n"); (void)read_helpline(debuglvl, &about_list, "Nicolas Dejardin <zephura(at)free(dot)fr> (French translation).\n"); (void)read_helpline(debuglvl, &about_list, "Adi Kriegisch (coding, documentation, Debian packages).\n"); (void)read_helpline(debuglvl, &about_list, "Sebastian Marten (documentation).\n"); (void)read_helpline(debuglvl, &about_list, "Holger Ohmacht (German translation).\n"); (void)read_helpline(debuglvl, &about_list, "Hugo Ribeiro (Brazilian Portuguese translation).\n"); (void)read_helpline(debuglvl, &about_list, "Aleksandr Shubnik <alshu(at)tut(dot)by> (rpm development, Russian translation).\n"); (void)read_helpline(debuglvl, &about_list, "Per Olav Siggerud (Norwegian translation).\n"); (void)read_helpline(debuglvl, &about_list, "Alexandre Simon (coding).\n"); (void)read_helpline(debuglvl, &about_list, "Stefan Ubbink (Gentoo ebuilds, coding).\n"); (void)read_helpline(debuglvl, &about_list, "Rob de Wit (wiki hosting).\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "See: http://www.vuurmuur.org/trac/wiki/Credits for the latest information.\n"); (void)read_helpline(debuglvl, &about_list, "\n"); set_lines(debuglvl, &about_list, (size_t)(width - 4)); draw_top_menu(debuglvl, top_win, gettext("About"), key_choices_n, key_choices, cmd_choices_n, cmd_choices); /* print the status list */ print_list(debuglvl, &about_list, gettext("About"), height, width, starty, startx, UTF8_FALSE); vrmr_list_cleanup(debuglvl, &about_list); }
static int print_pkg(alpm_pkg_t *pkg, const char *format) { const char *f, *end; char fmt[64], buf[64]; int len, out = 0; end = format + strlen(format); for (f = format; f < end; f++) { len = 0; if (*f == '%') { len = strspn(f + 1 + len, printf_flags); len += strspn(f + 1 + len, digits); snprintf(fmt, len + 3, "%ss", f); fmt[len + 1] = 's'; f += len + 1; switch (*f) { /* simple attributes */ case 'f': /* filename */ out += printf(fmt, alpm_pkg_get_filename(pkg)); break; case 'n': /* package name */ out += printf(fmt, alpm_pkg_get_name(pkg)); break; case 'v': /* version */ out += printf(fmt, alpm_pkg_get_version(pkg)); break; case 'd': /* description */ out += printf(fmt, alpm_pkg_get_desc(pkg)); break; case 'u': /* project url */ out += printf(fmt, alpm_pkg_get_url(pkg)); break; case 'p': /* packager name */ out += printf(fmt, alpm_pkg_get_packager(pkg)); break; case 's': /* md5sum */ out += printf(fmt, alpm_pkg_get_md5sum(pkg)); break; case 'a': /* architecutre */ out += printf(fmt, alpm_pkg_get_arch(pkg)); break; case 'i': /* has install scriptlet? */ out += printf(fmt, alpm_pkg_has_scriptlet(pkg) ? "yes" : "no"); break; case 'r': /* repo */ out += printf(fmt, alpm_db_get_name(alpm_pkg_get_db(pkg))); break; case 'w': /* install reason */ out += printf(fmt, alpm_pkg_get_reason(pkg) ? "dependency" : "explicit"); break; case '!': /* result number */ snprintf(buf, sizeof(buf), "%d", opt_pkgcounter++); out += printf(fmt, buf); break; case 'g': /* base64 gpg sig */ out += printf(fmt, alpm_pkg_get_base64_sig(pkg)); break; case 'h': /* sha256sum */ out += printf(fmt, alpm_pkg_get_sha256sum(pkg)); break; /* times */ case 'b': /* build date */ out += print_time(alpm_pkg_get_builddate(pkg)); break; case 'l': /* install date */ out += print_time(alpm_pkg_get_installdate(pkg)); break; /* sizes */ case 'k': /* download size */ out += printf(fmt, size_to_string(alpm_pkg_get_size(pkg))); break; case 'm': /* install size */ out += printf(fmt, size_to_string(alpm_pkg_get_isize(pkg))); break; /* lists */ case 'F': /* files */ out += print_filelist(alpm_pkg_get_files(pkg)); break; case 'N': /* requiredby */ out += print_list(alpm_pkg_compute_requiredby(pkg), NULL); break; case 'L': /* licenses */ out += print_list(alpm_pkg_get_licenses(pkg), NULL); break; case 'G': /* groups */ out += print_list(alpm_pkg_get_groups(pkg), NULL); break; case 'E': /* depends (shortdeps) */ out += print_list(alpm_pkg_get_depends(pkg), (extractfn)alpm_dep_get_name); break; case 'D': /* depends */ out += print_list(alpm_pkg_get_depends(pkg), (extractfn)alpm_dep_compute_string); break; case 'O': /* optdepends */ out += print_list(alpm_pkg_get_optdepends(pkg), (extractfn)format_optdep); break; case 'o': /* optdepends (shortdeps) */ out += print_list(alpm_pkg_get_optdepends(pkg), (extractfn)alpm_dep_get_name); break; case 'C': /* conflicts */ out += print_list(alpm_pkg_get_conflicts(pkg), (extractfn)alpm_dep_get_name); break; case 'S': /* provides (shortdeps) */ out += print_list(alpm_pkg_get_provides(pkg), (extractfn)alpm_dep_get_name); break; case 'P': /* provides */ out += print_list(alpm_pkg_get_provides(pkg), (extractfn)alpm_dep_compute_string); break; case 'R': /* replaces */ out += print_list(alpm_pkg_get_replaces(pkg), (extractfn)alpm_dep_get_name); break; case 'B': /* backup */ out += print_list(alpm_pkg_get_backup(pkg), alpm_backup_get_name); break; case 'V': /* package validation */ out += print_allocated_list(get_validation_method(pkg), NULL); break; case 'M': /* modified */ out += print_allocated_list(get_modified_files(pkg), NULL); break; case '%': fputc('%', stdout); out++; break; default: fputc('?', stdout); out++; break; } } else if (*f == '\\') { char esc[3] = { f[0], f[1], '\0' }; out += print_escaped(esc); ++f; } else { fputc(*f, stdout); out++; } } /* only print a delimeter if any package data was outputted */ if (out > 0) { print_escaped(opt_delim); } return !out; }
/* Print list to file by applying print to each node that is not NULL */ void print_list(void (*print)(FILE *f, void *data), FILE *f, List list) { if (list) { print(f, list->data); print_list(print, f, list->next); } }
static void print_list(const SList *list, char *buf, s_erc *error) { SIterator *itr; size_t list_size; S_CLR_ERR(error); list_size = SListSize(list, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"list_size\" failed")) return; s_strcat(buf, "[", error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"s_strcat\" failed")) return; itr = S_ITERATOR_GET(list, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"S_ITERATOR_GET\" failed")) return; for (/* NOP */; itr != NULL; itr = SIteratorNext(itr), --list_size) { s_bool type_ok; const SObject *tmp; tmp = SIteratorObject(itr, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"SIteratorObject\" failed")) { S_DELETE(itr, "print_list", error); return; } type_ok = SObjectIsType(tmp, "SList", error); if (S_CHK_ERR(error, S_CONTERR, "print_word", "Call to \"SObjectIsType\" failed")) { S_DELETE(itr, "print_list", error); return; } if (type_ok) { print_list(S_LIST(tmp), buf, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"print_list\" failed")) { S_DELETE(itr, "print_list", error); return; } } else { type_ok = SObjectIsType(tmp, "SString", error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"SObjectIsType\" failed")) { S_DELETE(itr, "print_list", error); return; } if (type_ok) { const char *string = SObjectGetString(S_OBJECT(tmp), error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"SObjectGetString\" failed")) { S_DELETE(itr, "print_list", error); return; } s_strcat(buf, string, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"s_strcat\" failed")) { S_DELETE(itr, "print_list", error); return; } if ((list_size-1) != 0) { s_strcat(buf, " ", error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"s_strcat\" failed")) { S_DELETE(itr, "print_list", error); return; } } } else { S_CTX_ERR(error, S_FAILURE, "print_list", "Unknown type in list"); { S_DELETE(itr, "print_list", error); return; } } } } s_strcat(buf, "]", error); S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"s_strcat\" failed"); }
int createClientEndpoint(const char *host, const char *service,EndpointInfo *info) { int sd, result, x=-1; struct addrinfo hints, *res =NULL, *tmp=NULL; if(host==NULL || service==NULL) { fprintf(stderr, "host and client can't be NULL\n"); return -1; } memset(&hints, 0, sizeof(struct addrinfo)); if(info->type==UDPEndpoint) hints.ai_socktype=SOCK_DGRAM; else if(info->type==TCPEndpoint) hints.ai_socktype=SOCK_STREAM; result=getaddrinfo(host, service,&hints,&res); if (result != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(result)); return -1; } if (res->ai_addrlen > sizeof(struct sockaddr_storage))/*perritos elegxos*/ { fprintf(stderr, "sockaddr too large\n"); freeaddrinfo(res); res = NULL; return -1; } info->sd=malloc(10); info->sdlen = 0; print_list(res); for(tmp=res; tmp; tmp=tmp->ai_next) { //info->sd[0] sd=socket(tmp->ai_family,tmp->ai_socktype,tmp->ai_protocol); printf("socket id %d \n",sd); if(sd==-1) { fprintf(stderr, "socket failed :%d %s\n",errno,strerror(errno)); continue; } if(info->type==TCPEndpoint) { x=connect(sd,tmp->ai_addr,tmp->ai_addrlen); if(x<0) { /*connect didn't make it*/ close(sd); fprintf(stderr, "connect failed :%s\n",strerror(errno)); /*will try to connect to another socket*/ continue; } /*connect success*/ //printf("socket id:%d connected succsfully(connect returned %d) \n",sd,x); } /*connect success*/ info->sd[info->sdlen] = sd; info->sdlen ++; break; } if(info->sdlen == 0) { freeaddrinfo(res); fprintf(stderr, "Client :: couldn'create Endpoint.\n"); return -1; } info->sd = (int*)malloc(sizeof(int)); info->sd[0] = sd; info->addr=res; return 0; }
/* uncompress the given file and remove the original */ static off_t file_uncompress(char *file, char *outfile, size_t outsize) { struct stat isb, osb; off_t size; ssize_t rbytes; unsigned char header1[4]; enum filetype method; int fd, ofd, zfd = -1; #ifndef SMALL ssize_t rv; time_t timestamp = 0; char name[PATH_MAX + 1]; #endif /* gather the old name info */ fd = open(file, O_RDONLY); if (fd < 0) { maybe_warn("can't open %s", file); goto lose; } strlcpy(outfile, file, outsize); if (check_suffix(outfile, 1) == NULL && !(cflag || lflag)) { maybe_warnx("%s: unknown suffix -- ignored", file); goto lose; } rbytes = read(fd, header1, sizeof header1); if (rbytes != sizeof header1) { /* we don't want to fail here. */ #ifndef SMALL if (fflag) goto lose; #endif if (rbytes == -1) maybe_warn("can't read %s", file); else goto unexpected_EOF; goto lose; } method = file_gettype(header1); #ifndef SMALL if (fflag == 0 && method == FT_UNKNOWN) { maybe_warnx("%s: not in gzip format", file); goto lose; } #endif #ifndef SMALL if (method == FT_GZIP && Nflag) { unsigned char ts[4]; /* timestamp */ rv = pread(fd, ts, sizeof ts, GZIP_TIMESTAMP); if (rv >= 0 && rv < (ssize_t)(sizeof ts)) goto unexpected_EOF; if (rv == -1) { if (!fflag) maybe_warn("can't read %s", file); goto lose; } timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0]; if (header1[3] & ORIG_NAME) { rbytes = pread(fd, name, sizeof(name) - 1, GZIP_ORIGNAME); if (rbytes < 0) { maybe_warn("can't read %s", file); goto lose; } if (name[0] != '\0') { char *dp, *nf; /* Make sure that name is NUL-terminated */ name[rbytes] = '\0'; /* strip saved directory name */ nf = strrchr(name, '/'); if (nf == NULL) nf = name; else nf++; /* preserve original directory name */ dp = strrchr(file, '/'); if (dp == NULL) dp = file; else dp++; snprintf(outfile, outsize, "%.*s%.*s", (int) (dp - file), file, (int) rbytes, nf); } } } #endif lseek(fd, 0, SEEK_SET); if (cflag == 0 || lflag) { if (fstat(fd, &isb) != 0) goto lose; #ifndef SMALL if (isb.st_nlink > 1 && lflag == 0 && fflag == 0) { maybe_warnx("%s has %d other links -- skipping", file, isb.st_nlink - 1); goto lose; } if (nflag == 0 && timestamp) isb.st_mtime = timestamp; if (check_outfile(outfile) == 0) goto lose; #endif } if (cflag == 0 && lflag == 0) { zfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0600); if (zfd == STDOUT_FILENO) { /* We won't close STDOUT_FILENO later... */ zfd = dup(zfd); close(STDOUT_FILENO); } if (zfd == -1) { maybe_warn("can't open %s", outfile); goto lose; } #ifndef SMALL remove_file = outfile; #endif } else zfd = STDOUT_FILENO; switch (method) { #ifndef NO_BZIP2_SUPPORT case FT_BZIP2: /* XXX */ if (lflag) { maybe_warnx("no -l with bzip2 files"); goto lose; } size = unbzip2(fd, zfd, NULL, 0, NULL); break; #endif #ifndef NO_COMPRESS_SUPPORT case FT_Z: { FILE *in, *out; /* XXX */ if (lflag) { maybe_warnx("no -l with Lempel-Ziv files"); goto lose; } if ((in = zdopen(fd)) == NULL) { maybe_warn("zdopen for read: %s", file); goto lose; } out = fdopen(dup(zfd), "w"); if (out == NULL) { maybe_warn("fdopen for write: %s", outfile); fclose(in); goto lose; } size = zuncompress(in, out, NULL, 0, NULL); /* need to fclose() if ferror() is true... */ if (ferror(in) | fclose(in)) { maybe_warn("failed infile fclose"); unlink(outfile); (void)fclose(out); } if (fclose(out) != 0) { maybe_warn("failed outfile fclose"); unlink(outfile); goto lose; } break; } #endif #ifndef NO_PACK_SUPPORT case FT_PACK: if (lflag) { maybe_warnx("no -l with packed files"); goto lose; } size = unpack(fd, zfd, NULL, 0, NULL); break; #endif #ifndef NO_XZ_SUPPORT case FT_XZ: if (lflag) { maybe_warnx("no -l with xz files"); goto lose; } size = unxz(fd, zfd, NULL, 0, NULL); break; #endif #ifndef SMALL case FT_UNKNOWN: if (lflag) { maybe_warnx("no -l for unknown filetypes"); goto lose; } size = cat_fd(NULL, 0, NULL, fd); break; #endif default: if (lflag) { print_list(fd, isb.st_size, outfile, isb.st_mtime); close(fd); return -1; /* XXX */ } size = gz_uncompress(fd, zfd, NULL, 0, NULL, file); break; } if (close(fd) != 0) maybe_warn("couldn't close input"); if (zfd != STDOUT_FILENO && close(zfd) != 0) maybe_warn("couldn't close output"); if (size == -1) { if (cflag == 0) unlink(outfile); maybe_warnx("%s: uncompress failed", file); return -1; } /* if testing, or we uncompressed to stdout, this is all we need */ #ifndef SMALL if (tflag) return size; #endif /* if we are uncompressing to stdin, don't remove the file. */ if (cflag) return size; /* * if we create a file... */ /* * if we can't stat the file don't remove the file. */ ofd = open(outfile, O_RDWR, 0); if (ofd == -1) { maybe_warn("couldn't open (leaving original): %s", outfile); return -1; } if (fstat(ofd, &osb) != 0) { maybe_warn("couldn't stat (leaving original): %s", outfile); close(ofd); return -1; } if (osb.st_size != size) { maybe_warnx("stat gave different size: %ju != %ju (leaving original)", (uintmax_t)size, (uintmax_t)osb.st_size); close(ofd); unlink(outfile); return -1; } #ifndef SMALL copymodes(ofd, &isb, outfile); remove_file = NULL; #endif close(ofd); unlink_input(file, &isb); return size; unexpected_EOF: maybe_warnx("%s: unexpected end of file", file); lose: if (fd != -1) close(fd); if (zfd != -1 && zfd != STDOUT_FILENO) close(fd); return -1; }
/*将中缀表达式转换成后缀表达式 *@parm: sexpr 中缀表达式 *return: 存储后缀表达式的队列 **/ List convert_postfix_expression(char *expr) { List queue_exp; //后缀表达式队列,也作为操作数队列 List stack_opr; //运算符栈 char temp[25]; int i; char *pstr, *p; queue_exp = stack_opr = NULL; while(*expr != '\0') { //扫描整个中缀表达式 //isoperand = FALSE; i = 0; if(isdigit(*expr) || *expr == '.') { //是操作数(实数) memset(temp, 0, sizeof(temp)); while(isdigit(*expr) || *expr == '.') { //考虑操作数是多位的情况 temp[i++] = *expr++; }/*while*/ PNEW(pstr, i); strcpy(pstr, temp); queue_exp = list_push(queue_exp, pstr); //操作数入队列 }else { //是运算符 PNEW(pstr, OPERATOR_LEN); switch(*expr) { case '(': //左括号直接压入操作符栈 *pstr = '('; stack_opr = list_push(stack_opr, pstr); break; case '+': case '-': case '*': case '/': if(list_length(stack_opr)) {//操作符优先级比较 //当前运算符,小于栈顶运算符 while(priority(*expr) <= priority(*((char *)stack_opr->ptr))) { stack_opr = list_pop(stack_opr, &p); //取出优先级高的栈顶运算符 queue_exp = list_push(queue_exp, p); //入队 if(list_length(stack_opr) == 0) break; //如果栈顶为空,退出while }/*while*/ }/*if*/ //当前运算符进栈 *pstr = *expr; stack_opr = list_push(stack_opr, pstr); break; case ')': /*取出运算符栈中左小括号以 上得全部运算符压入操作符队列中 */ while(*((char *)stack_opr->ptr) != '(') { stack_opr = list_pop(stack_opr, &p); //出栈 queue_exp = list_push(queue_exp, p); //入队 }/*while*/ stack_opr = list_pop(stack_opr, &p); //丢掉'(' free(p); break; default : printf("----------%c\n",*expr); assert(!"expression format is error\n"); break; }/*switch*/ expr++; }/*else*/ #if DEBUG print_list(queue_exp, "queue"); print_list(stack_opr, "stack"); #endif }/*while*/ //将操作符全部压入操作数队列中 while(list_length(stack_opr)) { stack_opr = list_pop(stack_opr, &p); //出栈 queue_exp = list_push(queue_exp, p); //入队 } #if DEBUG print_list(queue_exp, "queue"); print_list(stack_opr, "stack"); #endif return queue_exp; }
int main(int argc, char **argv) { int choix=0; int value=0; printf("%s",menu); fflush(stdout); while(1) { fflush(stdin); choix = getchar(); printf("\n"); switch(choix) { case 'T' : case 't' : printf("Valeur du nouvel element ? "); scanf("%d",&value); if (insert_head(&la_liste,value)!=0) { printf("Erreur : impossible d'ajouter l'element %d\n",value); }; break; case 'Q' : case 'q' : printf("Valeur du nouvel element ? "); scanf("%d",&value); if (insert_tail(&la_liste,value)!=0) { printf("Erreur : impossible d'ajouter l'element %d\n",value); }; break; case 'F' : case 'f' : printf("Index de l'element a rechercher ? "); scanf("%d", &value); list_elem_t* result = find_element(la_liste, value); if(result != NULL) printf("La valeur de l'element numero %d est %d\n", value, result->value); else printf("Erreur, l'element numero %d n'existe pas\n", value); break; case 's' : case 'S' : printf("Valeur de l'element a supprimer ? "); scanf("%d", &value); if(remove_element(&la_liste, value) != 0) printf("Erreur, aucun element ne possede la valeur %d\n", value); else printf("L'element de valeur %d a ete supprime avec succes\n", value); break; case 'r' : case 'R' : printf("Renversement des elements de la liste.\n"); reverse_list(&la_liste); break; case 'x' : case 'X' : return 0; default: break; } print_list(la_liste); if (nb_malloc!=list_size(la_liste)) { printf("\nAttention : il y a une fuite memoire dans votre programme !\n"); printf("la liste contient %d element, or il y a %d element vivant en memoire !\n",list_size(la_liste),nb_malloc); } getchar(); // pour consommer un RC et eviter un double affichage du menu ! printf("%s\n",menu); } return 0; }
int main (void) { struct node* head = add_node(33); print_list(head); return 0; }
float caculate(List queue_postfix) { List stack_sum; //栈,存储操作数 float f1, f2; //二元运算符两边的操作数 char *p, *psum; psum = p = NULL; stack_sum = NULL; f1 = f2 = 0; #if DEBUG print_list(queue_postfix, "postfix_queue"); #endif //逆置队列后可以使用pop()方法取队尾元素 queue_postfix = list_reverse(queue_postfix); #if DEBUG print_list(queue_postfix, "postfix_queue"); #endif //循环遍历队列元素 while(list_length(queue_postfix)) { queue_postfix = list_pop(queue_postfix, &p); //取出队尾元素 if((isdigit(*p)) || (*p == '.')) { //操作数 stack_sum = list_push(stack_sum, p); //压栈 }else { //运算符 stack_sum = list_pop(stack_sum, &psum); f2 = atof(psum); //参与运算的第二个操作数 free(psum); psum = NULL; stack_sum = list_pop(stack_sum, &psum); f1 = atof(psum); //参与运算的第一个操作数 free(psum); psum = NULL; switch(*p) { case '+': f1 += f2; break; case '-': f1 -= f2; break; case '*': f1 *= f2; break; case '/': if(f2 == 0) assert(!"div by zero error\n"); //除0错误 f1 /= f2; break; default: assert(!"expression fromat erorr\n"); break; }/*switch*/ PNEW(psum, OPERAND_LEN); sprintf(psum, "%f", f1); stack_sum = list_push(stack_sum, psum); //将计算结果压栈 }/*else*/ }/*while*/ stack_sum = list_pop(stack_sum, &psum); //将最后的计算结果出栈 return atof(psum); }
static void handle_sigwinch(void) { signal(SIGWINCH, SIG_IGN); print_list(); signal(SIGWINCH, &signal_handler); }
void print_key2(redis_instance* inst, char* key, size_t len) { long long size = 0; int flag = get_key_type(inst, key, len); long long pttl = get_key_pttl(inst, key, len); printf("{key:%s, type:%s, pttl:%lldms, db:%lu,", key, type_name[flag], pttl, inst->db); switch (flag) { case KSTRING: { redisReply* kv = (redisReply*)redisCommand(inst->cxt, "get %b", key, len); assert(kv != nil); assert(kv->type == REDIS_REPLY_STRING); assert(kv->len != 0); pline(" value:%s}", kv->str); freeReplyObject(kv); } break; case KHASH: { size = get_hashtable_size(inst, key, len); printf(" size:%lld", size); if (size) { printf(",\n kvs:["); print_hashtable2(inst, key, len); pline("\b \n ]"); } pline("}"); } break; case KLIST: { size = get_list_size(inst, key, len); printf(" size:%lld", size); if (size) { printf(",\n values:["); print_list(inst, key, len); pline("\b \n ]"); } pline("}"); } break; case KSET: { size = get_set_size(inst, key, len); printf(" size:%lld", size); if (size) { printf(",\n values:["); print_set2(inst, key, len); pline("\b \n ]"); } pline("}"); } break; case KSSET: { size = get_sset_size(inst, key, len); printf(" size:%lld", size); if (size) { printf(",\n values:["); print_sset2(inst, key, len); pline("\b \n ]"); } pline("}"); } break; case KNONE: { FATAL("none type of key:%s", key); } break; case KUNKOWN: { FATAL("unknown type of key:%s", key); } } }
/** * int print_stats() * * Function to print results after algo is ran */ int print_stats(Algorithm algo) { print_summary(algo); print_list(algo.data->page_table.lh_first, "Frame #", "Page Ref"); return 0; }
int main(){ int choice,i; int v1,v2; do{ printf("Choose the option:\n"); printf("1.Create new empty graph\n"); printf("2.Add edge\n"); printf("3.Delete edge\n"); printf("4.bfs\n"); printf("5.dfs\n"); printf("6.Increment graph-size\n"); printf("7.Print list"); printf("Enter any other integer to exit\n"); scanf("%d",&choice); printf("You entered:%d\n",choice); switch(choice){ case 1: if(graph) choice=delete_graph(); if(choice){ printf("Enter the initial number of nodes you want in the graph\n"); scanf("%d",&node_count); graph=(node**)malloc(node_count*sizeof(node*)); if(graph){ printf("Empty graph of size:%d created\n",node_count); for(i=0;i<node_count;i++){ graph[i]=(node*)malloc(sizeof(node)); graph[i]->data=i; graph[i]->next=NULL; } break; } printf("Error allocating memory for empty graph of size:%d,try again...\n",node_count); break; } case 2: if(!graph){ printf("First Create a new empty graph\n"); break; } printf("Enter the two vertices to add edge between them\n"); scanf("%d%d",&v1,&v2); add_edge(v1,v2); break; case 3: if(!graph){ printf("First Create a new empty graph\n"); break; } printf("Enter the two vertices to delete edge between them\n"); scanf("%d%d",&v1,&v2); delete_edge(v1,v2); break; case 4: if(!graph){ printf("First Create a new empty graph\n"); break; } printf("Enter the vertex to start bfs from\n"); scanf("%d",&v1); bfs(v1); break; case 5: if(!graph){ printf("First Create a new empty graph\n"); break; } printf("Enter the vertex to start dfs from\n"); scanf("%d",&v1); dfs(v1); break; case 6: if(!graph){ printf("First Create a new empty graph\n"); break; } printf("Enter the new size of the graph you want\n"); scanf("%d",&choice); increment_graphsize(choice); break; case 7: if(!graph){ printf("First Create a new empty graph\n"); break; } print_list(); break; default: printf("Exiting\n"); return 0; } }while(true); return 0; }
int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request) { pListitem match; Comm *mycomm; Req *rreq, *sreq; mycomm=mpi_handle_to_ptr(comm); /* mycomm=(Comm *)comm; */ #ifdef INFO fflush(stdout); fprintf(stderr,"MPI_Irecv: Comm=%d tag=%d count=%d type=%d\n", mycomm->num,tag,count,datatype); #endif if (source!=0 && source!=MPI_ANY_SOURCE && source!=MPI_PROC_NULL) { fprintf(stderr,"MPI_Irecv: bad source %d\n",source); abort(); } mpi_alloc_handle(request,(void **)&rreq); if (source==MPI_PROC_NULL) { rreq->complete=1; rreq->source=MPI_PROC_NULL; rreq->tag=MPI_ANY_TAG; return(MPI_SUCCESS); } if ( match=AP_list_search_func(mycomm->sendlist,mpi_match_send,&tag) ) { sreq=(Req *)AP_listitem_data(match); AP_list_delete_item(mycomm->sendlist,match); memcpy(buf,sreq->buf,count * datatype); rreq->complete=1; rreq->source=0; rreq->tag=sreq->tag; /* in case tag was MPI_ANY_TAG */ sreq->complete=1; #ifdef DEBUG printf("Completion(recv) value=%d tag=%d\n", *((int *)buf),rreq->tag); #endif return(MPI_SUCCESS); } rreq->buf=buf; rreq->tag=tag; rreq->complete=0; rreq->listitem=AP_list_append(mycomm->recvlist,rreq); #ifdef INFO print_list(mycomm->recvlist,"recvlist for comm ",mycomm->num); #endif return(MPI_SUCCESS); }
static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list) { int OK = 0; int gaa_last_non_option; struct GAAOPTION_priority GAATMP_priority; struct GAAOPTION_ctypes GAATMP_ctypes; struct GAAOPTION_kx GAATMP_kx; struct GAAOPTION_macs GAATMP_macs; struct GAAOPTION_comp GAATMP_comp; struct GAAOPTION_protocols GAATMP_protocols; struct GAAOPTION_ciphers GAATMP_ciphers; struct GAAOPTION_opaque_prf_input GAATMP_opaque_prf_input; struct GAAOPTION_srppasswdconf GAATMP_srppasswdconf; struct GAAOPTION_srppasswd GAATMP_srppasswd; struct GAAOPTION_pskhint GAATMP_pskhint; struct GAAOPTION_pskpasswd GAATMP_pskpasswd; struct GAAOPTION_x509dsacertfile GAATMP_x509dsacertfile; struct GAAOPTION_x509dsakeyfile GAATMP_x509dsakeyfile; struct GAAOPTION_x509certfile GAATMP_x509certfile; struct GAAOPTION_x509keyfile GAATMP_x509keyfile; struct GAAOPTION_pgpsubkey GAATMP_pgpsubkey; struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile; struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile; struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring; struct GAAOPTION_x509crlfile GAATMP_x509crlfile; struct GAAOPTION_x509cafile GAATMP_x509cafile; struct GAAOPTION_dhparams GAATMP_dhparams; struct GAAOPTION_port GAATMP_port; struct GAAOPTION_debug GAATMP_debug; #line 393 "gaa.skel" #ifdef GAA_REST_EXISTS struct GAAREST GAAREST_tmp; #endif opt_list[gaa_num] = 1; for(gaa_last_non_option = gaa_index; (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION); gaa_last_non_option++); if(gaa_num == GAA_REST) { gaa_index = 1; gaa_last_non_option = GAAargc; } switch(gaa_num) { case GAAOPTID_version: OK = 0; #line 121 "serv.gaa" { serv_version(); exit(0); ;}; return GAA_OK; break; case GAAOPTID_help: OK = 0; #line 119 "serv.gaa" { gaa_help(); exit(0); ;}; return GAA_OK; break; case GAAOPTID_list: OK = 0; #line 118 "serv.gaa" { print_list(0); exit(0); ;}; return GAA_OK; break; case GAAOPTID_priority: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_priority.arg1, gaa_getstr, GAATMP_priority.size1); gaa_index++; #line 116 "serv.gaa" { gaaval->priorities = GAATMP_priority.arg1 ;}; return GAA_OK; break; case GAAOPTID_ctypes: OK = 0; GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1); #line 113 "serv.gaa" { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;}; return GAA_OK; break; case GAAOPTID_kx: OK = 0; GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1); #line 109 "serv.gaa" { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;}; return GAA_OK; break; case GAAOPTID_macs: OK = 0; GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1); #line 105 "serv.gaa" { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;}; return GAA_OK; break; case GAAOPTID_comp: OK = 0; GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1); #line 101 "serv.gaa" { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;}; return GAA_OK; break; case GAAOPTID_protocols: OK = 0; GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1); #line 97 "serv.gaa" { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;}; return GAA_OK; break; case GAAOPTID_ciphers: OK = 0; GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1); #line 93 "serv.gaa" { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;}; return GAA_OK; break; case GAAOPTID_opaque_prf_input: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_opaque_prf_input.arg1, gaa_getstr, GAATMP_opaque_prf_input.size1); gaa_index++; #line 89 "serv.gaa" { gaaval->opaque_prf_input = GAATMP_opaque_prf_input.arg1 ;}; return GAA_OK; break; case GAAOPTID_srppasswdconf: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_srppasswdconf.arg1, gaa_getstr, GAATMP_srppasswdconf.size1); gaa_index++; #line 86 "serv.gaa" { gaaval->srp_passwd_conf = GAATMP_srppasswdconf.arg1 ;}; return GAA_OK; break; case GAAOPTID_srppasswd: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1); gaa_index++; #line 83 "serv.gaa" { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;}; return GAA_OK; break; case GAAOPTID_pskhint: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pskhint.arg1, gaa_getstr, GAATMP_pskhint.size1); gaa_index++; #line 80 "serv.gaa" { gaaval->psk_hint = GAATMP_pskhint.arg1 ;}; return GAA_OK; break; case GAAOPTID_pskpasswd: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pskpasswd.arg1, gaa_getstr, GAATMP_pskpasswd.size1); gaa_index++; #line 77 "serv.gaa" { gaaval->psk_passwd = GAATMP_pskpasswd.arg1 ;}; return GAA_OK; break; case GAAOPTID_disable_client_cert: OK = 0; #line 74 "serv.gaa" { gaaval->disable_client_cert = 1 ;}; return GAA_OK; break; case GAAOPTID_require_cert: OK = 0; #line 71 "serv.gaa" { gaaval->require_cert = 1 ;}; return GAA_OK; break; case GAAOPTID_x509dsacertfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509dsacertfile.arg1, gaa_getstr, GAATMP_x509dsacertfile.size1); gaa_index++; #line 68 "serv.gaa" { gaaval->x509_dsacertfile = GAATMP_x509dsacertfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509dsakeyfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509dsakeyfile.arg1, gaa_getstr, GAATMP_x509dsakeyfile.size1); gaa_index++; #line 65 "serv.gaa" { gaaval->x509_dsakeyfile = GAATMP_x509dsakeyfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509certfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1); gaa_index++; #line 62 "serv.gaa" { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509keyfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1); gaa_index++; #line 59 "serv.gaa" { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_pgpsubkey: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pgpsubkey.arg1, gaa_getstr, GAATMP_pgpsubkey.size1); gaa_index++; #line 56 "serv.gaa" { gaaval->pgp_subkey = GAATMP_pgpsubkey.arg1 ;}; return GAA_OK; break; case GAAOPTID_pgpcertfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1); gaa_index++; #line 53 "serv.gaa" { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_pgpkeyfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1); gaa_index++; #line 50 "serv.gaa" { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_pgpkeyring: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1); gaa_index++; #line 47 "serv.gaa" { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509crlfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1); gaa_index++; #line 44 "serv.gaa" { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509cafile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1); gaa_index++; #line 41 "serv.gaa" { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509fmtder: OK = 0; #line 38 "serv.gaa" { gaaval->fmtder = 1 ;}; return GAA_OK; break; case GAAOPTID_dhparams: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_dhparams.arg1, gaa_getstr, GAATMP_dhparams.size1); gaa_index++; #line 35 "serv.gaa" { gaaval->dh_params_file = GAATMP_dhparams.arg1 ;}; return GAA_OK; break; case GAAOPTID_echo: OK = 0; #line 32 "serv.gaa" { gaaval->http = 0 ;}; return GAA_OK; break; case GAAOPTID_http: OK = 0; #line 31 "serv.gaa" { gaaval->http = 1 ;}; return GAA_OK; break; case GAAOPTID_noticket: OK = 0; #line 28 "serv.gaa" { gaaval->noticket = 1 ;}; return GAA_OK; break; case GAAOPTID_nodb: OK = 0; #line 25 "serv.gaa" { gaaval->nodb = 1 ;}; return GAA_OK; break; case GAAOPTID_quiet: OK = 0; #line 22 "serv.gaa" { gaaval->quiet = 1 ;}; return GAA_OK; break; case GAAOPTID_port: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1); gaa_index++; #line 19 "serv.gaa" { gaaval->port = GAATMP_port.arg1 ;}; return GAA_OK; break; case GAAOPTID_generate: OK = 0; #line 16 "serv.gaa" { gaaval->generate = 1 ;}; return GAA_OK; break; case GAAOPTID_debug: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1); gaa_index++; #line 13 "serv.gaa" { gaaval->debug = GAATMP_debug.arg1 ;}; return GAA_OK; break; #line 413 "gaa.skel" default: break; } return GAA_ERROR_UNKNOWN; }
static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list) { int OK = 0; int gaa_last_non_option; struct GAAOPTION_port GAATMP_port; struct GAAOPTION_opaque_prf_input GAATMP_opaque_prf_input; struct GAAOPTION_pskkey GAATMP_pskkey; struct GAAOPTION_pskusername GAATMP_pskusername; struct GAAOPTION_srppasswd GAATMP_srppasswd; struct GAAOPTION_srpusername GAATMP_srpusername; struct GAAOPTION_x509certfile GAATMP_x509certfile; struct GAAOPTION_x509keyfile GAATMP_x509keyfile; struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile; struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring; struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile; struct GAAOPTION_x509crlfile GAATMP_x509crlfile; struct GAAOPTION_x509cafile GAATMP_x509cafile; struct GAAOPTION_priority GAATMP_priority; struct GAAOPTION_ctypes GAATMP_ctypes; struct GAAOPTION_kx GAATMP_kx; struct GAAOPTION_macs GAATMP_macs; struct GAAOPTION_comp GAATMP_comp; struct GAAOPTION_protocols GAATMP_protocols; struct GAAOPTION_ciphers GAATMP_ciphers; struct GAAOPTION_recordsize GAATMP_recordsize; struct GAAOPTION_debug GAATMP_debug; #line 393 "gaa.skel" #ifdef GAA_REST_EXISTS struct GAAREST GAAREST_tmp; #endif opt_list[gaa_num] = 1; for(gaa_last_non_option = gaa_index; (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION); gaa_last_non_option++); if(gaa_num == GAA_REST) { gaa_index = 1; gaa_last_non_option = GAAargc; } switch(gaa_num) { case GAAOPTID_copyright: OK = 0; #line 117 "cli.gaa" { print_license(); exit(0); ;}; return GAA_OK; break; case GAAOPTID_version: OK = 0; #line 116 "cli.gaa" { cli_version(); exit(0); ;}; return GAA_OK; break; case GAAOPTID_help: OK = 0; #line 114 "cli.gaa" { gaa_help(); exit(0); ;}; return GAA_OK; break; case GAAOPTID_list: OK = 0; #line 113 "cli.gaa" { print_list(gaaval->verbose); exit(0); ;}; return GAA_OK; break; case GAAOPTID_insecure: OK = 0; #line 111 "cli.gaa" { gaaval->insecure = 1 ;}; return GAA_OK; break; case GAAOPTID_port: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_port.arg1, gaa_getstr, GAATMP_port.size1); gaa_index++; #line 108 "cli.gaa" { gaaval->port = GAATMP_port.arg1 ;}; return GAA_OK; break; case GAAOPTID_opaque_prf_input: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_opaque_prf_input.arg1, gaa_getstr, GAATMP_opaque_prf_input.size1); gaa_index++; #line 105 "cli.gaa" { gaaval->opaque_prf_input = GAATMP_opaque_prf_input.arg1 ;}; return GAA_OK; break; case GAAOPTID_pskkey: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pskkey.arg1, gaa_getstr, GAATMP_pskkey.size1); gaa_index++; #line 102 "cli.gaa" { gaaval->psk_key = GAATMP_pskkey.arg1 ;}; return GAA_OK; break; case GAAOPTID_pskusername: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pskusername.arg1, gaa_getstr, GAATMP_pskusername.size1); gaa_index++; #line 99 "cli.gaa" { gaaval->psk_username = GAATMP_pskusername.arg1 ;}; return GAA_OK; break; case GAAOPTID_srppasswd: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1); gaa_index++; #line 96 "cli.gaa" { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;}; return GAA_OK; break; case GAAOPTID_srpusername: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_srpusername.arg1, gaa_getstr, GAATMP_srpusername.size1); gaa_index++; #line 93 "cli.gaa" { gaaval->srp_username = GAATMP_srpusername.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509certfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1); gaa_index++; #line 90 "cli.gaa" { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509keyfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1); gaa_index++; #line 87 "cli.gaa" { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_pgpcertfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1); gaa_index++; #line 84 "cli.gaa" { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_pgpkeyring: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1); gaa_index++; #line 81 "cli.gaa" { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;}; return GAA_OK; break; case GAAOPTID_pgpkeyfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1); gaa_index++; #line 78 "cli.gaa" { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509crlfile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1); gaa_index++; #line 75 "cli.gaa" { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;}; return GAA_OK; break; case GAAOPTID_x509cafile: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1); gaa_index++; #line 72 "cli.gaa" { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;}; return GAA_OK; break; case GAAOPTID_priority: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_priority.arg1, gaa_getstr, GAATMP_priority.size1); gaa_index++; #line 69 "cli.gaa" { gaaval->priorities = GAATMP_priority.arg1 ;}; return GAA_OK; break; case GAAOPTID_ctypes: OK = 0; GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1); #line 66 "cli.gaa" { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;}; return GAA_OK; break; case GAAOPTID_kx: OK = 0; GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1); #line 62 "cli.gaa" { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;}; return GAA_OK; break; case GAAOPTID_macs: OK = 0; GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1); #line 58 "cli.gaa" { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;}; return GAA_OK; break; case GAAOPTID_comp: OK = 0; GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1); #line 54 "cli.gaa" { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;}; return GAA_OK; break; case GAAOPTID_protocols: OK = 0; GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1); #line 50 "cli.gaa" { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;}; return GAA_OK; break; case GAAOPTID_ciphers: OK = 0; GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1); #line 46 "cli.gaa" { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;}; return GAA_OK; break; case GAAOPTID_verbose: OK = 0; #line 42 "cli.gaa" { gaaval->verbose = 1 ;}; return GAA_OK; break; case GAAOPTID_recordsize: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_recordsize.arg1, gaa_getint, GAATMP_recordsize.size1); gaa_index++; #line 39 "cli.gaa" { gaaval->record_size = GAATMP_recordsize.arg1 ;}; return GAA_OK; break; case GAAOPTID_print_cert: OK = 0; #line 36 "cli.gaa" { gaaval->print_cert = 1 ;}; return GAA_OK; break; case GAAOPTID_disable_extensions: OK = 0; #line 33 "cli.gaa" { gaaval->disable_extensions = 1 ;}; return GAA_OK; break; case GAAOPTID_fingerprint: OK = 0; #line 30 "cli.gaa" { gaaval->fingerprint = 1 ;}; return GAA_OK; break; case GAAOPTID_x509fmtder: OK = 0; #line 27 "cli.gaa" { gaaval->fmtder = 1 ;}; return GAA_OK; break; case GAAOPTID_crlf: OK = 0; #line 24 "cli.gaa" { gaaval->crlf = 1 ;}; return GAA_OK; break; case GAAOPTID_starttls: OK = 0; #line 21 "cli.gaa" { gaaval->starttls = 1 ;}; return GAA_OK; break; case GAAOPTID_resume: OK = 0; #line 18 "cli.gaa" { gaaval->resume = 1 ;}; return GAA_OK; break; case GAAOPTID_debug: OK = 0; GAA_TESTMOREARGS; GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1); gaa_index++; #line 15 "cli.gaa" { gaaval->debug = GAATMP_debug.arg1 ;}; return GAA_OK; break; case GAA_REST: GAA_TESTMOREARGS; GAA_FILL(GAAREST_tmp.arg1, gaa_getstr, GAAREST_tmp.size1); gaa_index++; #line 120 "cli.gaa" { gaaval->rest_args = GAAREST_tmp.arg1; ;}; return GAA_OK; break; #line 413 "gaa.skel" default: break; } return GAA_ERROR_UNKNOWN; }
void jobs() { print_list(); return; }
/* Normal -S, install packages from AUR * returns 0 on success, -1 on failure */ static int sync_targets(CURL *curl, alpm_list_t *targets) { struct pw_hashdb *hashdb = build_hashdb(); struct pkgpair pkgpair; struct pkgpair *pkgpair_ptr; struct aurpkg_t *aurpkg; alpm_pkg_t *lpkg; alpm_list_t *i; alpm_list_t *reinstall, *new_packages, *upgrade, *downgrade, *not_aur; alpm_list_t *aurpkg_list, *final_targets; int vercmp; int joined = 0, ret = 0; reinstall = new_packages = upgrade = downgrade = aurpkg_list = not_aur = NULL; final_targets = NULL; if (!hashdb) { pw_fprintf(PW_LOG_ERROR, stderr, "Failed to create hashdb\n"); goto cleanup; } for (i = targets; i; i = i->next) { aurpkg_list = query_aur(curl, i->data, AUR_QUERY_INFO); if (!aurpkg_list) { not_aur = alpm_list_add(not_aur, i->data); goto free_aurpkg; } /* Check version string */ pkgpair.pkgname = i->data; pkgpair_ptr = hash_search(hashdb->aur, &pkgpair); /* Locally installed AUR */ if (pkgpair_ptr) { aurpkg = aurpkg_list->data; lpkg = pkgpair_ptr->pkg; vercmp = alpm_pkg_vercmp(aurpkg->version, alpm_pkg_get_version(lpkg)); if (vercmp > 0) { upgrade = alpm_list_add(upgrade, i->data); } else if (vercmp == 0) { reinstall = alpm_list_add(reinstall, i->data); } else { downgrade = alpm_list_add(downgrade, i->data); } } else { new_packages = alpm_list_add(new_packages, i->data); } free_aurpkg: alpm_list_free_inner(aurpkg_list, (alpm_list_fn_free) aurpkg_free); alpm_list_free(aurpkg_list); } if (not_aur) { printf("\n%sThese packages are not from the AUR:%s\n", color.bred, color.nocolor); print_list(not_aur); } if (downgrade) { printf("\n%sLocally installed but newer than AUR, ignoring:%s\n", color.bcyan, color.nocolor); print_list(downgrade); } if (reinstall) { printf("\n%sReinstalling:%s\n", color.byellow, color.nocolor); print_list(reinstall); } if (upgrade) { printf("\n%sUpgrading:%s\n", color.bblue, color.nocolor); print_list(upgrade); } if (new_packages) { printf("\n%sSyncing:%s\n", color.bmag, color.nocolor); print_list(new_packages); } printf("\n"); if (config->noconfirm || yesno("Do you wish to proceed?")) { final_targets = alpm_list_join(reinstall, upgrade); final_targets = alpm_list_join(final_targets, new_packages); joined = 1; ret = upgrade_pkgs(final_targets, hashdb); } cleanup: hashdb_free(hashdb); alpm_list_free(downgrade); alpm_list_free(not_aur); if (joined) { alpm_list_free(final_targets); } else { alpm_list_free(reinstall); alpm_list_free(new_packages); alpm_list_free(upgrade); } return ret; }
static void handle_stdin(void) { unsigned char header1[4]; off_t usize, gsize; enum filetype method; ssize_t bytes_read; #ifndef NO_COMPRESS_SUPPORT FILE *in; #endif #ifndef SMALL if (fflag == 0 && lflag == 0 && isatty(STDIN_FILENO)) { maybe_warnx("standard input is a terminal -- ignoring"); return; } #endif if (lflag) { struct stat isb; /* XXX could read the whole file, etc. */ if (fstat(STDIN_FILENO, &isb) < 0) { maybe_warn("fstat"); return; } print_list(STDIN_FILENO, isb.st_size, "stdout", isb.st_mtime); return; } bytes_read = read_retry(STDIN_FILENO, header1, sizeof header1); if (bytes_read == -1) { maybe_warn("can't read stdin"); return; } else if (bytes_read != sizeof(header1)) { maybe_warnx("(stdin): unexpected end of file"); return; } method = file_gettype(header1); switch (method) { default: #ifndef SMALL if (fflag == 0) { maybe_warnx("unknown compression format"); return; } usize = cat_fd(header1, sizeof header1, &gsize, STDIN_FILENO); break; #endif case FT_GZIP: usize = gz_uncompress(STDIN_FILENO, STDOUT_FILENO, (char *)header1, sizeof header1, &gsize, "(stdin)"); break; #ifndef NO_BZIP2_SUPPORT case FT_BZIP2: usize = unbzip2(STDIN_FILENO, STDOUT_FILENO, (char *)header1, sizeof header1, &gsize); break; #endif #ifndef NO_COMPRESS_SUPPORT case FT_Z: if ((in = zdopen(STDIN_FILENO)) == NULL) { maybe_warnx("zopen of stdin"); return; } usize = zuncompress(in, stdout, (char *)header1, sizeof header1, &gsize); fclose(in); break; #endif #ifndef NO_PACK_SUPPORT case FT_PACK: usize = unpack(STDIN_FILENO, STDOUT_FILENO, (char *)header1, sizeof header1, &gsize); break; #endif #ifndef NO_XZ_SUPPORT case FT_XZ: usize = unxz(STDIN_FILENO, STDOUT_FILENO, (char *)header1, sizeof header1, &gsize); break; #endif } #ifndef SMALL if (vflag && !tflag && usize != -1 && gsize != -1) print_verbage(NULL, NULL, usize, gsize); if (vflag && tflag) print_test("(stdin)", usize != -1); #endif }
static void interpret(char *name, char *val, int comma, int rtype) { int type; while (*name == ' '||*name == '(') name++; /* Do some fixups */ if (rtype == AUDIT_EXECVE && name[0] == 'a') type = T_ESCAPED; else if (rtype == AUDIT_AVC && strcmp(name, "saddr") == 0) type = -1; else if (strcmp(name, "acct") == 0) { // Remove trailing punctuation int len = strlen(val); if (val[len-1] == ':') val[len-1] = 0; if (val[0] == '"') type = T_ESCAPED; else if (is_hex_string(val)) type = T_ESCAPED; else type = -1; } else type = audit_lookup_type(name); switch(type) { case T_UID: print_uid(val); break; case T_GID: print_gid(val); break; case T_SYSCALL: print_syscall(val); break; case T_ARCH: print_arch(val); break; case T_EXIT: print_exit(val); break; case T_ESCAPED: print_escaped(val); break; case T_PERM: print_perm(val); break; case T_MODE: print_mode(val); break; case T_SOCKADDR: print_sockaddr(val); break; case T_FLAGS: print_flags(val); break; case T_PROMISC: print_promiscuous(val); break; case T_CAPABILITY: print_capabilities(val); break; case T_SIGNAL: print_signals(val); break; case T_KEY: print_key(val); break; case T_LIST: print_list(val); break; case T_TTY_DATA: print_tty_data(val); break; default: printf("%s%c", val, comma ? ',' : ' '); } }
int main(int argc, char **argv) { List list; ListElmt *element; int *data, i; /***************************************************************************** * * * Initialize the linked list. * * * *****************************************************************************/ list_init(&list, free); /***************************************************************************** * * * Perform some linked list operations. * * * *****************************************************************************/ element = list_head(&list); for (i = 10; i > 0; i--) { if ((data = (int *)malloc(sizeof(int))) == NULL) return 1; *data = i; if (list_ins_next(&list, NULL, data) != 0) return 1; } print_list(&list); element = list_head(&list); for (i = 0; i < 7; i++) element = list_next(element); data = list_data(element); fprintf(stdout, "Removing an element after the one containing %03d\n", *data); if (list_rem_next(&list, element, (void **)&data) != 0) return 1; print_list(&list); fprintf(stdout, "Inserting 011 at the tail of the list\n"); *data = 11; if (list_ins_next(&list, list_tail(&list), data) != 0) return 1; print_list(&list); fprintf(stdout, "Removing an element after the first element\n"); element = list_head(&list); if (list_rem_next(&list, element, (void **)&data) != 0) return 1; print_list(&list); fprintf(stdout, "Inserting 012 at the head of the list\n"); *data = 12; if (list_ins_next(&list, NULL, data) != 0) return 1; print_list(&list); fprintf(stdout, "Iterating and removing the fourth element\n"); element = list_head(&list); element = list_next(element); element = list_next(element); if (list_rem_next(&list, element, (void **)&data) != 0) return 1; print_list(&list); fprintf(stdout, "Inserting 013 after the first element\n"); *data = 13; if (list_ins_next(&list, list_head(&list), data) != 0) return 1; print_list(&list); i = list_is_head(&list, list_head(&list)); fprintf(stdout, "Testing list_is_head...Value=%d (1=OK)\n", i); i = list_is_head(&list, list_tail(&list)); fprintf(stdout, "Testing list_is_head...Value=%d (0=OK)\n", i); i = list_is_tail(list_tail(&list)); fprintf(stdout, "Testing list_is_tail...Value=%d (1=OK)\n", i); i = list_is_tail(list_head(&list)); fprintf(stdout, "Testing list_is_tail...Value=%d (0=OK)\n", i); /***************************************************************************** * * * Destroy the linked list. * * * *****************************************************************************/ fprintf(stdout, "Destroying the list\n"); list_destroy(&list); return 0; }
int main(void) { snode n, *node; int rc, i = 0; slist_create(&s); // This first test checks to see if list is // created in a numeric order slist_add_if_uniq(&s, "test1"); slist_add_if_uniq(&s, "test2"); slist_first(&s); slist_add_if_uniq(&s, "test3"); puts("should be 3"); rc = print_list(); if (s.cnt != 3 || rc !=3) { puts("test count is wrong"); return 1; } n.str = strdup("test4"); n.key = NULL; n.hits = 1; slist_append(&s, &n); puts("should add a #4"); rc = print_list(); if (s.cnt != 4 || rc != 4) { puts("test count is wrong"); return 1; } slist_add_if_uniq(&s, "test2"); puts("should be same"); rc = print_list(); if (s.cnt != 4 || rc != 4) { puts("test count is wrong"); return 1; } slist_clear(&s); puts("should be empty"); rc = print_list(); if (s.cnt != 0 || rc != 0) { puts("test count is wrong"); return 1; } puts("starting sort test"); // Now test to see if the sort function works // Fill the list exactly backwards slist_add_if_uniq(&s, "test3"); slist_add_if_uniq(&s, "test3"); slist_add_if_uniq(&s, "test4"); slist_add_if_uniq(&s, "test3"); slist_add_if_uniq(&s, "test4"); slist_add_if_uniq(&s, "test2"); slist_add_if_uniq(&s, "test4"); slist_add_if_uniq(&s, "test2"); slist_add_if_uniq(&s, "test4"); slist_add_if_uniq(&s, "test1"); slist_sort_by_hits(&s); slist_first(&s); do { node = slist_get_cur(&s); if (node->hits != (4-i)) { printf("Sort test failed - i:%d != hits:%u\n", i, node->hits); return 1; } i++; } while ((node = slist_next(&s))); puts("sort test passes"); slist_clear(&s); return 0; }
main(){ struct node* head; makelist(&head); InsertNth(&head, 1, 11); print_list(head); }
void test_insert(struct node **head, int n) { printf("%2d:", n); insert_node(head, n); print_list(*head); }
static int print_allocated_list(alpm_list_t *list, extractfn fn) { int out = print_list(list, fn); alpm_list_free(list); return out; }
void print_list(const string &l, const std::vector<Expr> &args, const string &r) { stream << matched(l); print_list(args); stream << matched(r); }
int main(int argc, char **argv) { const char *progname = getprogname(); #ifndef SMALL char *gzip; int len; #endif int ch; /* XXX set up signals */ #ifndef SMALL if ((gzip = getenv("GZIP")) != NULL) prepend_gzip(gzip, &argc, &argv); #endif /* * XXX * handle being called `gunzip', `zcat' and `gzcat' */ if (strcmp(progname, "gunzip") == 0) dflag = 1; else if (strcmp(progname, "zcat") == 0 || strcmp(progname, "gzcat") == 0) dflag = cflag = 1; #ifdef SMALL #define OPT_LIST "123456789cdhlV" #else #define OPT_LIST "123456789cdfhklNnqrS:tVv" #endif while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1) { switch (ch) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': numflag = ch - '0'; break; case 'c': cflag = 1; break; case 'd': dflag = 1; break; case 'l': lflag = 1; dflag = 1; break; case 'V': display_version(); /* NOTREACHED */ #ifndef SMALL case 'f': fflag = 1; break; case 'k': kflag = 1; break; case 'N': nflag = 0; Nflag = 1; break; case 'n': nflag = 1; Nflag = 0; break; case 'q': qflag = 1; break; case 'r': rflag = 1; break; case 'S': len = strlen(optarg); if (len != 0) { if (len > SUFFIX_MAXLEN) errx(1, "incorrect suffix: '%s'", optarg); suffixes[0].zipped = optarg; suffixes[0].ziplen = len; } else { suffixes[NUM_SUFFIXES - 1].zipped = ""; suffixes[NUM_SUFFIXES - 1].ziplen = 0; } break; case 't': cflag = 1; tflag = 1; dflag = 1; break; case 'v': vflag = 1; break; #endif default: usage(); /* NOTREACHED */ } } argv += optind; argc -= optind; if (argc == 0) { if (dflag) /* stdin mode */ handle_stdin(); else /* stdout mode */ handle_stdout(); } else { do { handle_pathname(argv[0]); } while (*++argv); } #ifndef SMALL if (qflag == 0 && lflag && argc > 1) print_list(-1, 0, "(totals)", 0); #endif exit(exit_value); }
/* * This is an alternate interface to 'checklist' which allows the application * to read the list item states back directly without putting them in the * output buffer. It also provides for more than two states over which the * check/radio box can display. */ int dlg_checklist(const char *title, const char *cprompt, int height, int width, int list_height, int item_no, DIALOG_LISTITEM * items, const char *states, int flag, int *current_item) { /* *INDENT-OFF* */ static DLG_KEYS_BINDING binding[] = { HELPKEY_BINDINGS, ENTERKEY_BINDINGS, DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ), DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ), DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ), DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ), DLG_KEYS_DATA( DLGK_ITEM_FIRST, KEY_HOME ), DLG_KEYS_DATA( DLGK_ITEM_LAST, KEY_END ), DLG_KEYS_DATA( DLGK_ITEM_LAST, KEY_LL ), DLG_KEYS_DATA( DLGK_ITEM_NEXT, '+' ), DLG_KEYS_DATA( DLGK_ITEM_NEXT, KEY_DOWN ), DLG_KEYS_DATA( DLGK_ITEM_NEXT, CHR_NEXT ), DLG_KEYS_DATA( DLGK_ITEM_PREV, '-' ), DLG_KEYS_DATA( DLGK_ITEM_PREV, KEY_UP ), DLG_KEYS_DATA( DLGK_ITEM_PREV, CHR_PREVIOUS ), DLG_KEYS_DATA( DLGK_PAGE_NEXT, KEY_NPAGE ), DLG_KEYS_DATA( DLGK_PAGE_NEXT, DLGK_MOUSE(KEY_NPAGE) ), DLG_KEYS_DATA( DLGK_PAGE_PREV, KEY_PPAGE ), DLG_KEYS_DATA( DLGK_PAGE_PREV, DLGK_MOUSE(KEY_PPAGE) ), END_KEYS_BINDING }; /* *INDENT-ON* */ #ifdef KEY_RESIZE int old_height = height; int old_width = width; #endif ALL_DATA all; int i, j, key2, found, x, y, cur_x, cur_y; int key = 0, fkey; int button = dialog_state.visit_items ? -1 : dlg_default_button(); int choice = dlg_default_listitem(items); int scrollamt = 0; int max_choice; int was_mouse; int use_width, list_width, name_width, text_width; int result = DLG_EXIT_UNKNOWN; int num_states; WINDOW *dialog; char *prompt = dlg_strclone(cprompt); const char **buttons = dlg_ok_labels(); const char *widget_name; memset(&all, 0, sizeof(all)); all.items = items; all.item_no = item_no; dlg_does_output(); dlg_tab_correct_str(prompt); /* * If this is a radiobutton list, ensure that no more than one item is * selected initially. Allow none to be selected, since some users may * wish to provide this flavor. */ if (flag == FLAG_RADIO) { bool first = TRUE; for (i = 0; i < item_no; i++) { if (items[i].state) { if (first) { first = FALSE; } else { items[i].state = 0; } } } widget_name = "radiolist"; } else { widget_name = "checklist"; } #ifdef KEY_RESIZE retry: #endif all.use_height = list_height; use_width = dlg_calc_list_width(item_no, items) + 10; use_width = MAX(26, use_width); if (all.use_height == 0) { /* calculate height without items (4) */ dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, use_width); dlg_calc_listh(&height, &all.use_height, item_no); } else { dlg_auto_size(title, prompt, &height, &width, MIN_HIGH + all.use_height, use_width); } dlg_button_layout(buttons, &width); dlg_print_size(height, width); dlg_ctl_size(height, width); /* we need at least two states */ if (states == 0 || strlen(states) < 2) states = " *"; num_states = (int) strlen(states); all.states = states; all.checkflag = flag; x = dlg_box_x_ordinate(width); y = dlg_box_y_ordinate(height); dialog = dlg_new_window(height, width, y, x); all.dialog = dialog; dlg_register_window(dialog, widget_name, binding); dlg_register_buttons(dialog, widget_name, buttons); dlg_mouse_setbase(x, y); dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr); dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr); dlg_draw_title(dialog, title); (void) wattrset(dialog, dialog_attr); dlg_print_autowrap(dialog, prompt, height, width); all.use_width = width - 6; getyx(dialog, cur_y, cur_x); all.box_y = cur_y + 1; all.box_x = (width - all.use_width) / 2 - 1; /* * After displaying the prompt, we know how much space we really have. * Limit the list to avoid overwriting the ok-button. */ if (all.use_height + MIN_HIGH > height - cur_y) all.use_height = height - MIN_HIGH - cur_y; if (all.use_height <= 0) all.use_height = 1; max_choice = MIN(all.use_height, item_no); max_choice = MAX(max_choice, 1); /* create new window for the list */ all.list = dlg_sub_window(dialog, all.use_height, all.use_width, y + all.box_y + 1, x + all.box_x + 1); /* draw a box around the list items */ dlg_draw_box(dialog, all.box_y, all.box_x, all.use_height + 2 * MARGIN, all.use_width + 2 * MARGIN, menubox_border_attr, menubox_border2_attr); text_width = 0; name_width = 0; /* Find length of longest item to center checklist */ for (i = 0; i < item_no; i++) { text_width = MAX(text_width, dlg_count_columns(items[i].text)); name_width = MAX(name_width, dlg_count_columns(items[i].name)); } /* If the name+text is wider than the list is allowed, then truncate * one or both of them. If the name is no wider than 1/4 of the list, * leave it intact. */ use_width = (all.use_width - 6); if (dialog_vars.no_tags) { list_width = MIN(all.use_width, text_width); } else if (dialog_vars.no_items) { list_width = MIN(all.use_width, name_width); } else { if (text_width >= 0 && name_width >= 0 && use_width > 0 && text_width + name_width > use_width) { int need = (int) (0.25 * use_width); if (name_width > need) { int want = (int) (use_width * ((double) name_width) / (text_width + name_width)); name_width = (want > need) ? want : need; } text_width = use_width - name_width; } list_width = (text_width + name_width); } all.check_x = (use_width - list_width) / 2; all.item_x = ((dialog_vars.no_tags ? 0 : (dialog_vars.no_items ? 0 : (2 + name_width))) + all.check_x + 4); /* ensure we are scrolled to show the current choice */ scrollamt = MIN(scrollamt, max_choice + item_no - 1); if (choice >= (max_choice + scrollamt - 1)) { scrollamt = MAX(0, choice - max_choice + 1); choice = max_choice - 1; } print_list(&all, choice, scrollamt, max_choice); /* register the new window, along with its borders */ dlg_mouse_mkbigregion(all.box_y + 1, all.box_x, all.use_height, all.use_width + 2, KEY_MAX, 1, 1, 1 /* by lines */ ); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); dlg_trace_win(dialog); while (result == DLG_EXIT_UNKNOWN) { if (button < 0) /* --visit-items */ wmove(dialog, all.box_y + choice + 1, all.box_x + all.check_x + 2); key = dlg_mouse_wgetch(dialog, &fkey); if (dlg_result_key(key, fkey, &result)) break; was_mouse = (fkey && is_DLGK_MOUSE(key)); if (was_mouse) key -= M_EVENT; if (was_mouse && (key >= KEY_MAX)) { getyx(dialog, cur_y, cur_x); i = (key - KEY_MAX); if (i < max_choice) { choice = (key - KEY_MAX); print_list(&all, choice, scrollamt, max_choice); key = ' '; /* force the selected item to toggle */ } else { beep(); continue; } fkey = FALSE; } else if (was_mouse && key >= KEY_MIN) { key = dlg_lookup_key(dialog, key, &fkey); } /* * A space toggles the item status. We handle either a checklist * (any number of items can be selected) or radio list (zero or one * items can be selected). */ if (key == ' ') { int current = scrollamt + choice; int next = items[current].state + 1; if (next >= num_states) next = 0; if (flag == FLAG_CHECK) { /* checklist? */ getyx(dialog, cur_y, cur_x); items[current].state = next; print_item(&all, all.list, &items[scrollamt + choice], states, choice, TRUE); (void) wnoutrefresh(all.list); (void) wmove(dialog, cur_y, cur_x); } else { /* radiolist */ for (i = 0; i < item_no; i++) { if (i != current) { items[i].state = 0; } } if (items[current].state) { getyx(dialog, cur_y, cur_x); items[current].state = next ? next : 1; print_item(&all, all.list, &items[current], states, choice, TRUE); (void) wnoutrefresh(all.list); (void) wmove(dialog, cur_y, cur_x); } else { items[current].state = 1; print_list(&all, choice, scrollamt, max_choice); } } continue; /* wait for another key press */ } /* * Check if key pressed matches first character of any item tag in * list. If there is more than one match, we will cycle through * each one as the same key is pressed repeatedly. */ found = FALSE; if (!fkey) { if (button < 0 || !dialog_state.visit_items) { for (j = scrollamt + choice + 1; j < item_no; j++) { if (check_hotkey(items, j)) { found = TRUE; i = j - scrollamt; break; } } if (!found) { for (j = 0; j <= scrollamt + choice; j++) { if (check_hotkey(items, j)) { found = TRUE; i = j - scrollamt; break; } } } if (found) dlg_flush_getc(); } else if ((j = dlg_char_to_button(key, buttons)) >= 0) { button = j; ungetch('\n'); continue; } } /* * A single digit (1-9) positions the selection to that line in the * current screen. */ if (!found && (key <= '9') && (key > '0') && (key - '1' < max_choice)) { found = TRUE; i = key - '1'; } if (!found) { if (fkey) { found = TRUE; switch (key) { case DLGK_ITEM_FIRST: i = -scrollamt; break; case DLGK_ITEM_LAST: i = item_no - 1 - scrollamt; break; case DLGK_PAGE_PREV: if (choice) i = 0; else if (scrollamt != 0) i = -MIN(scrollamt, max_choice); else continue; break; case DLGK_PAGE_NEXT: i = MIN(choice + max_choice, item_no - scrollamt - 1); break; case DLGK_ITEM_PREV: i = choice - 1; if (choice == 0 && scrollamt == 0) continue; break; case DLGK_ITEM_NEXT: i = choice + 1; if (scrollamt + choice >= item_no - 1) continue; break; default: found = FALSE; break; } } } if (found) { if (i != choice) { getyx(dialog, cur_y, cur_x); if (i < 0 || i >= max_choice) { if (i < 0) { scrollamt += i; choice = 0; } else { choice = max_choice - 1; scrollamt += (i - max_choice + 1); } print_list(&all, choice, scrollamt, max_choice); } else { choice = i; print_list(&all, choice, scrollamt, max_choice); } } continue; /* wait for another key press */ } if (fkey) { switch (key) { case DLGK_ENTER: result = dlg_enter_buttoncode(button); break; case DLGK_FIELD_PREV: button = dlg_prev_button(buttons, button); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; case DLGK_FIELD_NEXT: button = dlg_next_button(buttons, button); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; #ifdef KEY_RESIZE case KEY_RESIZE: /* reset data */ height = old_height; width = old_width; /* repaint */ dlg_clear(); dlg_del_window(dialog); refresh(); dlg_mouse_free_regions(); goto retry; #endif default: if (was_mouse) { if ((key2 = dlg_ok_buttoncode(key)) >= 0) { result = key2; break; } beep(); } } } else { beep(); } } dlg_del_window(dialog); dlg_mouse_free_regions(); free(prompt); *current_item = (scrollamt + choice); return result; }