static GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_KEYGEN); while ((c = getopt_long(argc, argv, "dvf:VMp:sr:t:hl:", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': KEY_PATH = optarg; break; case 'd': DEBUG = true; break; case 'V': PrintVersionBanner("cf-key"); exit(0); case 'v': VERBOSE = true; break; case 'p': /* print digest */ print_digest_arg = optarg; break; case 's': SHOWHOSTS = true; break; case 'r': REMOVEKEYS = true; remove_keys_host = optarg; break; case 'l': LICENSE_INSTALL = true; strlcpy(LICENSE_SOURCE, optarg, sizeof(LICENSE_SOURCE)); break; case 't': trust_key_arg = optarg; break; case 'h': Syntax("cf-key - CFEngine's key generator", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-key - CFEngine's key generator", OPTIONS, HINTS, ID); exit(0); default: Syntax("cf-key - CFEngine's key generator", OPTIONS, HINTS, ID); exit(1); } } return config; }
GenericAgentConfig CheckOpts(int argc, char **argv) { extern char *optarg; int optindex = 0; int c; GenericAgentConfig config = GenericAgentDefaultConfig(cf_common); while ((c = getopt_long(argc, argv, "advnIf:D:N:VSrxMb:pg:h", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': if (optarg && strlen(optarg) < 5) { FatalError(" -f used but argument \"%s\" incorrect", optarg); } SetInputFile(optarg); MINUSF = true; break; case 'd': NewClass("opt_debug"); DEBUG = true; break; case 'b': if (optarg) { config.bundlesequence = SplitStringAsRList(optarg, ','); CBUNDLESEQUENCE_STR = optarg; } break; case 'K': IGNORELOCK = true; break; case 'D': NewClassesFromString(optarg); break; case 'N': NegateClassesFromString(optarg); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; break; case 'n': DONTDO = true; IGNORELOCK = true; LOOKUP = true; NewClass("opt_dry_run"); break; case 'V': PrintVersionBanner("cf-promises"); exit(0); case 'h': Syntax("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID); exit(0); case 'r': PrependRScalar(&GOALS, "goal.*", CF_SCALAR); SHOWREPORTS = true; break; case 'x': SelfDiagnostic(); exit(0); case 'a': printf("Self-analysis is not yet implemented.\n"); exit(0); break; /* case 'p': SHOW_PARSE_TREE = true; break; */ case 'g': USE_GCC_BRIEF_FORMAT = true; break; default: Syntax("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID); exit(1); } } if (argv[optind] != NULL) { CfOut(cf_error, "", "Unexpected argument with no preceding option: %s\n", argv[optind]); } CfDebug("Set debugging\n"); return config; }
int main(int argc, char **argv) { char *file_name = NULL; int i; XtAppContext xtcontext; Arg topLevelArgs[2]; Widget entry; XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); toplevel = XtAppInitialize(&xtcontext, "Xditview", options, XtNumber (options), &argc, argv, NULL, NULL, 0); if (argc > 2) Syntax(argv[0]); XtAppAddActions(xtcontext, xditview_actions, XtNumber (xditview_actions)); XtOverrideTranslations (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: Quit()")); XtSetArg (topLevelArgs[0], XtNiconPixmap, XCreateBitmapFromData (XtDisplay (toplevel), XtScreen(toplevel)->root, (char *) xdit_bits, xdit_width, xdit_height)); XtSetArg (topLevelArgs[1], XtNiconMask, XCreateBitmapFromData (XtDisplay (toplevel), XtScreen(toplevel)->root, (char *) xdit_mask_bits, xdit_mask_width, xdit_mask_height)); XtSetValues (toplevel, topLevelArgs, 2); if (argc > 1) file_name = argv[1]; /* * create the popup menu and insert the entries */ popupMenu = XtCreatePopupShell ("popupMenu", simpleMenuWidgetClass, toplevel, NULL, 0); for (i = 0; i < XtNumber (popupMenuEntries); i++) { entry = XtCreateManagedWidget(popupMenuEntries[i].name, smeBSBObjectClass, popupMenu, NULL, (Cardinal) 0); XtAddCallback(entry, XtNcallback, popupMenuEntries[i].function, NULL); } paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel, NULL, (Cardinal) 0); menuBar = XtCreateManagedWidget ("menuBar", boxWidgetClass, paned, NULL, 0); fileMenuButton = XtCreateManagedWidget ("fileMenuButton", menuButtonWidgetClass, menuBar, NULL, (Cardinal) 0); fileMenu = XtCreatePopupShell ("fileMenu", simpleMenuWidgetClass, fileMenuButton, NULL, (Cardinal) 0); for (i = 0; i < XtNumber (fileMenuEntries); i++) { entry = XtCreateManagedWidget(fileMenuEntries[i].name, smeBSBObjectClass, fileMenu, NULL, (Cardinal) 0); XtAddCallback (entry, XtNcallback, fileMenuEntries[i].function, NULL); } (void) XtCreateManagedWidget ("prevButton", commandWidgetClass, menuBar, NULL, (Cardinal) 0); pageNumber = XtCreateManagedWidget("pageNumber", asciiTextWidgetClass, menuBar, NULL, (Cardinal) 0); (void) XtCreateManagedWidget ("nextButton", commandWidgetClass, menuBar, NULL, (Cardinal) 0); #ifdef NOTDEF form = XtCreateManagedWidget ("form", formWidgetClass, paned, NULL, (Cardinal) 0); panner = XtCreateManagedWidget ("panner", pannerWidgetClass, form, NULL, 0); porthole = XtCreateManagedWidget ("porthole", portholeWidgetClass, form, NULL, 0); XtAddCallback(porthole, XtNreportCallback, PortholeCallback, (XtPointer) panner); XtAddCallback(panner, XtNreportCallback, PannerCallback, (XtPointer) porthole); #else porthole = XtCreateManagedWidget ("viewport", viewportWidgetClass, paned, NULL, 0); #endif dvi = XtCreateManagedWidget ("dvi", dviWidgetClass, porthole, NULL, 0); if (file_name) VisitFile (file_name, FALSE); XtRealizeWidget (toplevel); wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False); (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), &wm_delete_window, 1); XtAppMainLoop(xtcontext); return 0; }
int main( int argc , char *argv[] ) { THD_3dim_dataset *dset=NULL; int iarg , verbose = -1 ; char *outbuf, *stmp=NULL; char *labelName = NULL; char *sbdelim = {"|"}; char *NAflag = {"NA"}; char *atrdelim = {"\t"}, *form=NULL; INFO_FIELDS sing[512]; int iis=0, N_sing = 0, isb=0, withhead = 0, itmp=0; int ip=0, needpair = 0, namelen=0, monog_pairs = 0; THD_3dim_dataset *tttdset=NULL, *dsetp=NULL; char *tempstr = NULL; int extinit = 0; float RL_AP_IS[6]; mainENTRY("3dinfo main") ; machdep() ; if( argc < 2) { Syntax(TXT,1) ; RETURN(0); } iarg = 1 ; while (iarg < argc && argv[iarg][0] == '-') { CHECK_HELP(argv[iarg],Syntax); if( strncmp(argv[iarg],"-verb" ,5) == 0 ){ verbose = 0; iarg++; continue; } else if( strncmp(argv[iarg],"-VERB" ,5) == 0 ){ verbose = 1; iarg++; continue; } else if( strncmp(argv[iarg],"-short",5) == 0 ){ verbose = -1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-header_line") == 0 || strcasecmp(argv[iarg],"-hdr") == 0 ){ withhead = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-monog_pairs") == 0 ){ monog_pairs = 1; iarg++; continue; } else if ( strncmp(argv[iarg],"-label2",7) == 0 ) { iarg++; if (iarg >= argc) ERROR_exit( "3dinfo needs an argument after -label2number\n"); labelName = malloc(sizeof(char) * 2048); strcpy(labelName, argv[iarg]); iarg++; continue; } else if( strcasecmp(argv[iarg],"-sb_delim") == 0) { iarg++; if (iarg >= argc) ERROR_exit( "3dinfo needs a string after -sb_delim\n"); sbdelim = argv[iarg]; iarg++; continue; } else if( strcasecmp(argv[iarg],"-NA_flag") == 0) { iarg++; if (iarg >= argc) ERROR_exit( "3dinfo needs a string after -NA_flag\n"); NAflag = argv[iarg]; iarg++; continue; } else if( strcasecmp(argv[iarg],"-atr_delim") == 0) { iarg++; if (iarg >= argc) ERROR_exit( "3dinfo needs a string after -atr_delim\n"); atrdelim = argv[iarg]; iarg++; continue; } else if( strcasecmp(argv[iarg],"-space") == 0) { sing[N_sing++] = DSET_SPACE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-av_space") == 0) { sing[N_sing++] = AV_DSET_SPACE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-gen_space") == 0) { sing[N_sing++] = DSET_GEN_SPACE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-is_nifti") == 0) { sing[N_sing++] = IS_NIFTI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-is_atlas") == 0) { sing[N_sing++] = IS_ATLAS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-exists") == 0) { sing[N_sing++] = DSET_EXISTS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-is_oblique") == 0) { sing[N_sing++] = IS_OBLIQUE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-obliquity") == 0) { sing[N_sing++] = OBLIQUITY; iarg++; continue; } else if( strcasecmp(argv[iarg],"-handedness") == 0) { sing[N_sing++] = HANDEDNESS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-prefix") == 0) { sing[N_sing++] = PREFIX; iarg++; continue; } else if( strcasecmp(argv[iarg],"-prefix_noext") == 0) { sing[N_sing++] = PREFIX_NOEXT; iarg++; continue; } else if( strcasecmp(argv[iarg],"-ni") == 0) { sing[N_sing++] = NI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nj") == 0) { sing[N_sing++] = NJ; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nk") == 0) { sing[N_sing++] = NK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-n4") == 0) { sing[N_sing++] = NI; sing[N_sing++] = NJ; sing[N_sing++] = NK; sing[N_sing++] = NV; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Rextent") == 0) { sing[N_sing++] = EXTENT_R; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Lextent") == 0) { sing[N_sing++] = EXTENT_L; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Aextent") == 0) { sing[N_sing++] = EXTENT_A; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Pextent") == 0) { sing[N_sing++] = EXTENT_P; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Iextent") == 0) { sing[N_sing++] = EXTENT_I; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Sextent") == 0) { sing[N_sing++] = EXTENT_S; iarg++; continue; } else if( strcasecmp(argv[iarg],"-extent") == 0) { sing[N_sing++] = EXTENT_R; sing[N_sing++] = EXTENT_L; sing[N_sing++] = EXTENT_A; sing[N_sing++] = EXTENT_P; sing[N_sing++] = EXTENT_I; sing[N_sing++] = EXTENT_S; iarg++; continue; } else if( strcasecmp(argv[iarg],"-di") == 0) { sing[N_sing++] = DI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dj") == 0) { sing[N_sing++] = DJ; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dk") == 0) { sing[N_sing++] = DK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-d3") == 0) { sing[N_sing++] = DI; sing[N_sing++] = DJ; sing[N_sing++] = DK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-adi") == 0) { sing[N_sing++] = ADI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-adj") == 0) { sing[N_sing++] = ADJ; iarg++; continue; } else if( strcasecmp(argv[iarg],"-adk") == 0) { sing[N_sing++] = ADK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-ad3") == 0) { sing[N_sing++] = ADI; sing[N_sing++] = ADJ; sing[N_sing++] = ADK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-voxvol") == 0) { sing[N_sing++] = VOXVOL; iarg++; continue; } else if( strcasecmp(argv[iarg],"-iname") == 0) { sing[N_sing++] = INAME; iarg++; continue; } else if( strcasecmp(argv[iarg],"-oi") == 0) { sing[N_sing++] = OI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-oj") == 0) { sing[N_sing++] = OJ; iarg++; continue; } else if( strcasecmp(argv[iarg],"-ok") == 0) { sing[N_sing++] = OK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-o3") == 0) { sing[N_sing++] = OI; sing[N_sing++] = OJ; sing[N_sing++] = OK; iarg++; continue; }else if( strcasecmp(argv[iarg],"-nt") == 0) { sing[N_sing++] = NT; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nti") == 0) { sing[N_sing++] = NTI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nv") == 0) { sing[N_sing++] = NV; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nvi") == 0) { sing[N_sing++] = NVI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-ntimes") == 0) { sing[N_sing++] = NTIMES; iarg++; continue; } else if( strcasecmp(argv[iarg],"-max_node") == 0) { sing[N_sing++] = MAX_NODE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nijk") == 0) { sing[N_sing++] = NIJK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-labeltable") == 0) { sing[N_sing++] = LTABLE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-labeltable_as_atlas_points") == 0) { sing[N_sing++] = LTABLE_AS_ATLAS_POINT_LIST; iarg++; continue; } else if( strcasecmp(argv[iarg],"-atlas_points") == 0) { sing[N_sing++] = ATLAS_POINTS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-fac") == 0) { sing[N_sing++] = FAC; iarg++; continue; } else if( strcasecmp(argv[iarg],"-datum") == 0) { sing[N_sing++] = DATUM; iarg++; continue; } else if( strcasecmp(argv[iarg],"-label") == 0) { sing[N_sing++] = LABEL; iarg++; continue; } else if( strcasecmp(argv[iarg],"-min") == 0) { sing[N_sing++] = MIN; iarg++; continue; } else if( strcasecmp(argv[iarg],"-max") == 0) { sing[N_sing++] = MAX; iarg++; continue; } else if( strcasecmp(argv[iarg],"-minus") == 0) { sing[N_sing++] = MINUS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-maxus") == 0) { sing[N_sing++] = MAXUS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dmin") == 0) { sing[N_sing++] = DMIN; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dmax") == 0) { sing[N_sing++] = DMAX; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dminus") == 0) { sing[N_sing++] = DMINUS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dmaxus") == 0) { sing[N_sing++] = DMAXUS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-TR") == 0) { sing[N_sing++] = TR; iarg++; continue; } else if( strcasecmp(argv[iarg],"-header_name") == 0) { sing[N_sing++] = HEADER_NAME; iarg++; continue; } else if( strcasecmp(argv[iarg],"-brick_name") == 0) { sing[N_sing++] = BRICK_NAME; iarg++; continue; } else if( strcasecmp(argv[iarg],"-history") == 0) { sing[N_sing++] = HISTORY; iarg++; continue; } else if( strcasecmp(argv[iarg],"-all_names") == 0) { sing[N_sing++] = ALL_NAMES; iarg++; continue; } else if( strcasecmp(argv[iarg],"-orient") == 0) { sing[N_sing++] = ORIENT; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_grid") == 0) { sing[N_sing++] = SAME_GRID; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_dim") == 0) { sing[N_sing++] = SAME_DIM; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_delta") == 0) { sing[N_sing++] = SAME_DELTA; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_orient") == 0) { sing[N_sing++] = SAME_ORIENT; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_center") == 0) { sing[N_sing++] = SAME_CENTER; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_obl") == 0) { sing[N_sing++] = SAME_OBL; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-slice_timing") == 0) { sing[N_sing++] = SLICE_TIMING; iarg++; continue; } else if( strcasecmp(argv[iarg],"-sval_diff") == 0) { sing[N_sing++] = SVAL_DIFF; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-val_diff") == 0) { sing[N_sing++] = VAL_DIFF; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_all_grid") == 0) { sing[N_sing++] = SAME_DIM; sing[N_sing++] = SAME_DELTA; sing[N_sing++] = SAME_ORIENT; sing[N_sing++] = SAME_CENTER; sing[N_sing++] = SAME_OBL; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-id") == 0) { sing[N_sing++] = ID; iarg++; continue; } else if( strcasecmp(argv[iarg],"-smode") == 0) { sing[N_sing++] = SMODE; iarg++; continue; } else { ERROR_message("Option %s unknown", argv[iarg]); suggest_best_prog_option(argv[0], argv[iarg]); exit(1); } } if (N_sing == 0) { sing[N_sing++] = CLASSIC; } if (sing[iis] == CLASSIC) PRINT_VERSION("3dinfo") ; THD_allow_empty_dataset(1) ; /* 21 Mar 2007 */ if (iarg == argc) { ERROR_message("No dsets on command line? I have nothing to do.\n"); exit(1); } if (needpair && monog_pairs) needpair = 2; /* pair each couple separately */ if (needpair==2 && (argc-iarg) % 2) { ERROR_message("Using options requiring dset pairs but have odd number\n" "of dsets (%d) on command line.\n", (argc-iarg)); exit (1); } else if (needpair==1 && (argc-iarg) < 2) { ERROR_message("Using options requiring dset pairs but have less than\n" "two dsets (%d) on command line.\n", (argc-iarg)); exit (1); } ip = 0; for( ; iarg < argc ; iarg++ ){ if (ip == 0) { int kkk, nml; char *etr; namelen = 0; for (kkk=iarg; kkk<argc; ++kkk) { if ((etr = THD_trailname(argv[kkk],0))) { nml=strlen(etr); if (nml < 48 && nml > namelen) namelen = nml; } } if (namelen < 6) namelen = 6; if (withhead) { int havenew=0; for (iis = 0; iis < N_sing; ++iis) { if (sing[iis] != CLASSIC) { ++havenew; form = PrintForm(sing[iis], namelen, 1); /*fprintf(stderr,"ZSS: %d %s >%s<\n", sing[iis], Field_Names[sing[iis]], form);*/ fprintf(stdout, form, Field_Names[sing[iis]]); } if (havenew) { if (N_sing > 1 && iis < N_sing-1) fprintf(stdout,"%s",atrdelim); else fprintf(stdout,"\n"); } } } } if( argv[iarg][0] == '\0' ) continue ; /* bad filename */ set_obliquity_report(0); /* silence obliquity */ if (!needpair) { if (!(dset = load_3dinfo_dataset(argv[iarg]))) { /* exit(1); */ } } else { if (needpair == 2) { /* Crazy idea of comparing each pair separately */ if (ip % 2 == 0) { if (!(dset = load_3dinfo_dataset(argv[iarg] ))) { /* exit(1); */ } if (iarg+1==argc || argv[iarg+1][0] == '\0') { ERROR_message("Bad dset pair for %s\n", argv[iarg]); exit(1); } if (!(dsetp = load_3dinfo_dataset(argv[iarg+1] ))) { /* exit(1); */ } } else { /* swap the pair - this allows non pair requiring functions to work as before.*/ tttdset = dsetp; dsetp = dset; dset = tttdset; tttdset=NULL; } } else { /* always compare to very first dset */ if (ip==0) { if (!(dset = load_3dinfo_dataset(argv[iarg] ))) { /*exit(1);*/ } if (!(dsetp = load_3dinfo_dataset(argv[iarg+1] ))) { /*exit(1);*/ } } else if (ip==1) { /* switch order of first two */ tttdset = dsetp; dsetp = dset; /* now dsetp is the very first dset */ dset = tttdset; tttdset=NULL; } else { /* pair with very first, which is dsetp */ if (!(dset = load_3dinfo_dataset(argv[iarg] ))) { /*exit(1);*/ } } } } ++ip; if (0 && !dset) { /* allow for DSET_EXISTS option */ ERROR_exit("Should not get here"); } /* we should re-capture this per dataset 5 Feb 2019 [rickr] */ extinit = 0; for (iis = 0; iis < N_sing; ++iis) { if (!dset) { if (sing[iis] == CLASSIC) { if( dset == NULL ){ /* still not open? */ ERROR_exit("Can't open dataset %s\n", argv[iarg]) ; } } else if (sing[iis] != DSET_EXISTS && sing[iis] != INAME) { fprintf(stdout, "NO-DSET"); SPIT_DELIM(iis, N_sing, atrdelim); continue; } } switch (sing[iis]) { case CLASSIC: if (labelName == NULL ) /*** get and output info ***/ { outbuf = THD_dataset_info( dset , verbose ) ; if( outbuf != NULL ){ printf("\n") ; puts(outbuf) ; free(outbuf) ; outbuf = NULL ; } else { ERROR_exit("Can't get info for dataset %s",argv[iarg]) ; } } else /*** get and output label ***/ { int nval_per = dset->dblk->nvals; int foundLabel = 0; int ival=0; for (ival=0 ; ival < nval_per && !foundLabel; ival++ ) { if (strcmp(DSET_BRICK_LAB(dset,ival), labelName) == 0) { printf("%d\n", ival); foundLabel = 1; } } /* end of for (ival=0 ; ival < nval_per ; ival++ ) */ if (!foundLabel) printf("\n"); } THD_delete_3dim_dataset( dset , False ) ; free(labelName); break; case DSET_EXISTS: fprintf(stdout, "%d", dset ? 1:0); break; case DSET_SPACE: tempstr = THD_get_space(dset); if(tempstr==NULL) fprintf(stdout, "-----"); else fprintf(stdout, "%s", tempstr); break; case DSET_GEN_SPACE: tempstr = THD_get_generic_space(dset); if(tempstr==NULL) fprintf(stdout, "-----"); else fprintf(stdout, "%s", tempstr); break; case AV_DSET_SPACE: /* don't allow anything but the three AFNI views */ tempstr = THD_get_view_space(dset); if(tempstr==NULL) fprintf(stdout, "+orig"); else if (!strncasecmp(tempstr,"ORIG",4)) fprintf(stdout, "+orig"); else if (!strncasecmp(tempstr,"ACPC",4)) fprintf(stdout, "+acpc"); else if (!strncasecmp(tempstr,"TLRC",4)) fprintf(stdout, "+tlrc"); else /* shouldn't get here */ fprintf(stdout, "+orig"); break; case IS_NIFTI: if ( dset->dblk->diskptr && dset->dblk->diskptr->storage_mode == STORAGE_BY_NIFTI ) { fprintf(stdout,"1"); } else { fprintf(stdout,"0"); } break; case IS_ATLAS: if ( is_Dset_Atlasy(dset, NULL) ) { fprintf(stdout,"1"); } else { fprintf(stdout,"0"); } break; case IS_OBLIQUE: if (dset_obliquity(dset,NULL) > 0) { fprintf(stdout,"1"); } else { fprintf(stdout,"0"); } break; case HANDEDNESS: if (THD_handedness(dset) > 0) { fprintf(stdout,"R"); } else { fprintf(stdout,"L"); } break; case OBLIQUITY: fprintf(stdout,"%.3f", THD_compute_oblique_angle(dset->daxes->ijk_to_dicom_real, 0)); break; case PREFIX: form = PrintForm(sing[iis], namelen, 1); fprintf(stdout,form, DSET_PREFIX(dset)); break; case PREFIX_NOEXT: { form = PrintForm(sing[iis], namelen, 1); stmp=DSET_prefix_noext(dset); fprintf(stdout,form, stmp); free(stmp); stmp=NULL; } break; case HEADER_NAME: fprintf(stdout,"%s", dset->dblk->diskptr->header_name); break; case BRICK_NAME: fprintf(stdout,"%s", dset->dblk->diskptr->brick_name); break; case ALL_NAMES: THD_show_dataset_names(dset, "FOR_3DINFO", stdout); break; case HISTORY: stmp = tross_Get_History(dset); fprintf(stdout,"%s", stmp ? stmp:NAflag); if (stmp) free(stmp); stmp=NULL; break; case NI: fprintf(stdout,"%d", DSET_NX(dset)); break; case NJ: fprintf(stdout,"%d", DSET_NY(dset)); break; case NK: fprintf(stdout,"%d", DSET_NZ(dset)); break; case NIJK: fprintf(stdout,"%d", DSET_NVOX(dset)); break; case NTIMES: fprintf(stdout,"%d", DSET_NUM_TIMES(dset)); break; case MAX_NODE: DSET_MAX_NODE(dset,itmp); fprintf(stdout,"%d", itmp); break; case NT: case NV: fprintf(stdout,"%d", DSET_NVALS(dset)); break; case NTI: case NVI: fprintf(stdout,"%d", DSET_NVALS(dset)-1); break; case DI: fprintf(stdout,"%f", DSET_DX(dset)); break; case DJ: fprintf(stdout,"%f", DSET_DY(dset)); break; case DK: fprintf(stdout,"%f", DSET_DZ(dset)); break; case OI: fprintf(stdout,"%f", DSET_XORG(dset)); break; case OJ: fprintf(stdout,"%f", DSET_YORG(dset)); break; case OK: fprintf(stdout,"%f", DSET_ZORG(dset)); break; case ADI: fprintf(stdout,"%f", fabs(DSET_DX(dset))); break; case EXTENT_R: case EXTENT_L: case EXTENT_A: case EXTENT_P: case EXTENT_I: case EXTENT_S: { if (!extinit) { THD_dset_extent(dset, '-', RL_AP_IS); extinit = 1; } fprintf(stdout,"%f", RL_AP_IS[sing[iis]-EXTENT_R]); } break; case ADJ: fprintf(stdout,"%f", fabs(DSET_DY(dset))); break; case ADK: fprintf(stdout,"%f", fabs(DSET_DZ(dset))); break; case VOXVOL: fprintf(stdout,"%f", fabs(DSET_DX(dset))* fabs(DSET_DY(dset))*fabs(DSET_DZ(dset))); break; case INAME: fprintf(stdout,"%s", argv[iarg]); break; case LTABLE: { char *str; if ((str = Dtable_to_nimlstring(DSET_Label_Dtable(dset), "VALUE_LABEL_DTABLE"))) { fprintf(stdout,"%s", str); free(str); } else { fprintf(stdout,"NO_LABEL_TABLE"); } } break; case LTABLE_AS_ATLAS_POINT_LIST: { ATLAS_POINT_LIST *apl=NULL; if ((apl = label_table_to_atlas_point_list(DSET_Label_Dtable(dset)))) { atlas_list_to_niml(apl,NULL); free_atlas_point_list(apl); } else { fprintf(stdout,"NO_LABEL_TABLE"); } } break; case ATLAS_POINTS: { ATR_string *atr = THD_find_string_atr( dset->dblk, "ATLAS_LABEL_TABLE"); if (atr) { fprintf(stdout,"%s", atr->ch); } else { fprintf(stdout,"NO_APL"); } } break; case FAC: { for (isb=0; isb<DSET_NVALS(dset); ++isb) { fprintf(stdout,"%f%s", DSET_BRICK_FACTOR(dset,isb), (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } break; } case DATUM: { for (isb=0; isb<DSET_NVALS(dset); ++isb) { fprintf(stdout,"%s%s", MRI_TYPE_name[DSET_BRICK_TYPE(dset,isb)], (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } break; } case LABEL: { for (isb=0; isb<DSET_NVALS(dset); ++isb) { fprintf(stdout,"%s%s", DSET_BRICK_LABEL(dset,isb) ? DSET_BRICK_LABEL(dset,isb):NAflag, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } break; } case MIN: case MINUS: case MAX: case MAXUS: { float vv=0.0, min, max; for (isb=0; isb<DSET_NVALS(dset); ++isb) { if (!THD_subbrick_minmax(dset, isb, (sing[iis] == MINUS || sing[iis] == MAXUS) ? 0:1, &min, &max)) { fprintf(stdout,"%s%s", NAflag, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } else { if (sing[iis] == MINUS) vv = min; else if (sing[iis] == MAXUS) vv = max; else if (sing[iis] == MIN) vv = min; else if (sing[iis] == MAX) vv = max; fprintf(stdout,"%g%s", vv, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } } break; } case DMIN: case DMINUS: case DMAX: case DMAXUS: { float vv=0.0, min, max; if (!THD_dset_minmax(dset, (sing[iis] == DMINUS || sing[iis] == DMAXUS) ? 0:1, &min, &max)) { fprintf(stdout,"%s%s", NAflag, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } else { if (sing[iis] == DMINUS) vv = min; else if (sing[iis] == DMAXUS) vv = max; else if (sing[iis] == DMIN) vv = min; else if (sing[iis] == DMAX) vv = max; fprintf(stdout,"%g%s", vv, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } break; } case TR: #if 0 fprintf(stdout,"%f", DSET_TR_SEC(dset)); #else fprintf(stdout,"%f", DSET_TR(dset)); #endif break; case ORIENT: { /* fprintf(stdout,"%c%c%c", * ORIENT_typestr[dset->daxes->xxorient][0], ... ); */ char ostr[4]; /* just to show 23 Jan 2013 [rickr] */ THD_fill_orient_str_3(dset->daxes, ostr); fprintf(stdout,"%3s", ostr); } break; case SAME_GRID: fprintf(stdout,"%d", !THD_dataset_mismatch( dset , dsetp )); break; case SAME_DIM: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_DIMEN)); break; case SAME_DELTA: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_DELTA)); break; case SAME_ORIENT: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_ORIENT)); break; case SAME_CENTER: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_CENTER)); break; case SAME_OBL: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_OBLIQ)); break; case SLICE_TIMING: /* 6 May 2013 [rickr] */ { if( DSET_HAS_SLICE_TIMING(dset) ) { DSET_UNMSEC(dset); /* make sure times are in seconds */ for (isb=0; isb<dset->taxis->nsl; ++isb) { fprintf(stdout,"%s%f", (isb > 0) ? sbdelim : "", dset->taxis->toff_sl[isb]); } } else { /* all slices times are at t=0.0 */ for (isb=0; isb<DSET_NZ(dset); ++isb) { fprintf(stdout,"%s%f", (isb > 0) ? sbdelim : "", 0.0); } } } break; case SVAL_DIFF: fprintf(stdout,"%f",THD_diff_vol_vals(dset, dsetp, 1)); break; case VAL_DIFF: fprintf(stdout,"%f",THD_diff_vol_vals(dset, dsetp, 0)); break; case ID: fprintf(stdout,"%s", DSET_IDCODE_STR(dset)); break; case SMODE: fprintf(stdout,"%s", DSET_STORAGE_MODE_STR(dset)); break; default: ERROR_message("Info field not set properly (%d)\n", sing[iis]); exit(1); } if (sing[iis] != CLASSIC) { SPIT_DELIM(iis, N_sing, atrdelim); } } } exit(0) ; }
static void ParseParam(int argc, char *argv[], struct dynamo_param *param) { // Local variables char *pcOption; BOOL bParamIometer = FALSE; BOOL bParamDynamo = FALSE; int count = 0; ifstream devfile; // Walk through the parameter list for (int I = 1; I < argc; I++) { // NOTE: The following piece is from the Syntax() function: // =====BEGIN============================================ // // Solaris 2.7 must have the switch (? is used for its own purpose). // cout << "dynamo \\?" << endl; // =====END============================================== // Given Solaris 7 is pretty old (released in 1998), we // no longer support this option. If it is nevertheless // still needed, then add support back into the // ParseParam()and Syntax() function. // Ensure minimal parameter length if (strlen(argv[I]) < 2) { Syntax("Options must have a length of at least 2 characters."); return; } // Ensure that each parameter has a leading option indicator if (argv[I][0] == '-') { pcOption = &argv[I][1]; if (argv[I][1] == '-') { pcOption = &argv[I][2]; } } else { Syntax("Options must start with a leading option indicator (\"-\" or \"--\")."); return; } // Process parameters that have no argument // (alphabetic order; short options followed by long options) if (strcasecmp(pcOption, "?") == 0) { Syntax(); return; } if (strcasecmp(pcOption, "H") == 0 || strcasecmp(pcOption, "HELP") == 0) { Syntax(); return; } #if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_OSX) || defined(IOMTR_OS_SOLARIS) if (strcasecmp(pcOption, "L") == 0) { do_syslog = TRUE; openlog(NEW_WORKER_EXECUTABLE, 0, LOG_USER); continue; } #endif // Process parameters that have (an) argument(s) // (alphabetic order; short options followed by long options) I++; if (I >= argc) { Syntax("Options requires one or more argument(s)."); return; } #if defined (IOMTR_SETTING_CPU_AFFINITY) && (defined(IOMTR_OSFAMILY_WINDOWS) || defined(IOMTR_OS_LINUX)) if (strcasecmp(pcOption, "C") == 0) { if (argv[I]) { // Lets use sscanf below to support hex input ULONG_PTR tempMask = 0; // Handle both hex and decimal values. Abstract format spec syntax (in iocommon.h) if (argv[I][0] == '0' && argv[I][1] == 'x') sscanf(argv[I],"0x%" IOMTR_FORMAT_SPEC_64BIT "x", &tempMask); else sscanf(argv[I],"%" IOMTR_FORMAT_SPEC_64BIT "d", &tempMask); //#if defined (IOMTR_SETTING_CPU_AFFINITY) param->cpu_affinity = tempMask; //#endif } continue; } #endif #if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_OSX) || defined(IOMTR_OS_SOLARIS) if (strcasecmp(pcOption, "D") == 0) { if (check_dev(argv[I])) { Syntax("Not a valid device."); return; } if (count < MAX_TARGETS) { strcpy((*param->blkdevlist)[count++], argv[I]); } else { cout << "Too many targets you want to test, skip " << argv[I] << endl; } continue; } if (strcasecmp(pcOption, "F") == 0) { char devname[MAX_NAME]; devfile.open(argv[I]); if (!devfile.is_open()) { Syntax("Can not open device file list."); return; } while (!devfile.eof()) { memset(devname, 0, MAX_NAME); devfile.getline(devname, MAX_NAME - 1); if (check_dev(devname)) continue; if (count < MAX_TARGETS) { strcpy((*param->blkdevlist)[count++], devname); } else { cout << "Too many targets you want to test, skip " << devname << endl; } } continue; } #endif if (strcasecmp(pcOption, "I") == 0) { if (bParamIometer == TRUE) { Syntax("Iometer address was specified more than once."); return; } if (strlen(argv[I]) >= MAX_NETWORK_NAME) { Syntax("Iometer address parameter was too long."); return; } strcpy(param->iometer, argv[I]); bParamIometer = TRUE; continue; } if (strcasecmp(pcOption, "M") == 0) { // No check for more then once specification (as we have a default) if (strlen(argv[I]) >= MAX_NETWORK_NAME) { Syntax("Manager network name parameter was too long."); return; } strcpy(param->manager_computer_name, argv[I]); bParamDynamo = TRUE; continue; } if (strcasecmp(pcOption, "N") == 0) { if (param->manager_name[0] != '\0') { Syntax("Manager name was specified more than once."); return; } if (strlen(argv[I]) >= MAX_WORKER_NAME) { Syntax("Manager name parameter was too long."); return; } strcpy(param->manager_name, argv[I]); continue; } if (strcasecmp(pcOption, "P") == 0) { if (argv[I]) param->login_port_number = atoi(argv[I]); if (param->login_port_number < 1 || param->login_port_number > 65535) { Syntax("Port number was out of range."); param->login_port_number = 0; return; } continue; } #if defined(IOMTR_OS_LINUX) || defined(IOMTR_OSFAMILY_NETWARE) || defined(IOMTR_OS_OSX) || defined(IOMTR_OS_SOLARIS) if (strcasecmp(pcOption, "X") == 0) { if ((strlen(argv[I]) + strlen(param->manager_exclude_fs)) >= MAX_EXCLUDE_FILESYS) { Syntax("Excluded filesystem list too long."); return; } strcat(param->manager_exclude_fs, argv[I]); strcat(param->manager_exclude_fs, " "); continue; } #endif if (strcasecmp(pcOption, "FLAG") == 0) { if (strcasecmp(argv[I], "FORCE_RAW") == 0) { param->disk_control = RAWDISK_VIEW_FULL; cout << "Dynamo will display raw disks with valid partitions." << endl; continue; } #if defined(IOMTR_OSFAMILY_WINDOWS) || defined(IOMTR_OS_OSX) if (strcasecmp(argv[I], "USE_RDTSC") == 0) { param->timer_type = TIMER_RDTSC; // // Kludge, we don't really need the above param->timer_type since we can // directly access the TimerType global defines in IoTime.h. This should // be cleaned up better. // if (param->timer_type != TIMER_UNDEFINED && param->timer_type < TIMER_TYPE_MAX) { TimerType = (timer_type) param->timer_type; cout << "Dynamo will attempt to use the processor's high precision timer." << endl; } continue; } #endif // Unknown flag { char temp[256]; snprintf(temp, 256, "Flag unknown or not supported on this platform: %s", argv[I]); Syntax(temp); return; } } // Unknown parameter { char temp[256]; snprintf(temp, 256, "Option unknown or not supported on this platform: %s", argv[I-1]); Syntax(temp); return; } } // Enforce switch combinations if (bParamIometer && !bParamDynamo) { Syntax("Specifying the Iometer address, the Manager network name parameter becomes mandatory."); } cout << endl; // add one more newline. return; }
static GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_MONITOR); while ((c = getopt_long(argc, argv, "dvnIf:VSxHTKMFh", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': GenericAgentConfigSetInputFile(config, optarg); MINUSF = true; break; case 'd': config->debug_mode = true; NO_FORK = true; break; case 'K': IGNORELOCK = true; break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; NO_FORK = true; break; case 'F': NO_FORK = true; break; case 'H': /* Keep accepting this option for compatibility -- no longer used */ break; case 'T': MonNetworkSnifferEnable(true); break; case 'V': PrintVersionBanner("cf-monitord"); exit(0); case 'h': Syntax("cf-monitord - cfengine's monitoring agent", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-monitord - cfengine's monitoring agent", OPTIONS, HINTS, ID); exit(0); case 'x': CfOut(OUTPUT_LEVEL_ERROR, "", "Self-diagnostic functionality is retired."); exit(0); default: Syntax("cf-monitord - cfengine's monitoring agent", OPTIONS, HINTS, ID); exit(1); } } CfDebug("Set debugging\n"); return config; }
int main(int argc, char *argv[]) { extern char *optarg; int option_index = 0; int c; char *workdir = getenv("CFENGINE_TEST_OVERRIDE_WORKDIR"); snprintf(AVAILABLE_PACKAGES_FILE_NAME, 256, "%s/cfengine-mock-package-manager-available", workdir ? workdir : "/tmp"); snprintf(INSTALLED_PACKAGES_FILE_NAME, 256, "%s/cfengine-mock-package-manager-installed", workdir ? workdir : "/tmp"); while ((c = getopt_long(argc, argv, "", OPTIONS, &option_index)) != EOF) { PackagePattern *pattern = NULL; switch (c) { case 'c': ClearInstalledPackages(); break; case 'C': ClearAvailablePackages(); break; case 'l': { Rlist *installed_packages = ReadPackageEntries(INSTALLED_PACKAGES_FILE_NAME); ShowPackages(stdout, installed_packages); } break; case 'L': { Rlist *available_packages = ReadPackageEntries(AVAILABLE_PACKAGES_FILE_NAME); ShowPackages(stdout, available_packages); } break; case 'a': pattern = DeserializePackagePattern(optarg); AddPackage(pattern); break; case 'P': PopulateAvailable(optarg); break; /* case 'd': */ /* DeletePackage(pattern); */ /* break; */ /* case 'r': */ /* ReinstallPackage(pattern); */ /* break; */ /* case 'u': */ /* UpdatePackage(pattern); */ /* break; */ /* case 'U': */ /* AddUpdatePackage(pattern); */ /* break; */ /* case 'v': */ /* VerifyPackage(pattern); */ /* break; */ default: Syntax("mock-package-manager - pretend that you are managing packages!", OPTIONS, HINTS, ID); exit(1); } } return 0; }
void CheckOpts(int argc,char **argv) { extern char *optarg; int optindex = 0; int c; umask(077); sprintf(VPREFIX,"cfenvd"); openlog(VPREFIX,LOG_PID|LOG_NOWAIT|LOG_ODELAY,LOG_DAEMON); strcpy(CFLOCK,"cfenvd"); SetContext("cfenvd"); IGNORELOCK = false; OUTPUT[0] = '\0'; while ((c=getopt_long(argc,argv,"d:vhHFVT",CFDENVOPTIONS,&optindex)) != EOF) { switch ((char) c) { case 'd': switch ((optarg==NULL)?3:*optarg) { case '1': D1 = true; break; case '2': D2 = true; break; default: DEBUG = true; break; } NO_FORK = true; printf("cfenvd: Debug mode: running in foreground\n"); break; case 'v': VERBOSE = true; break; case 'V': printf("GNU %s-%s daemon\n%s\n",PACKAGE,VERSION,COPYRIGHT); printf("This program is covered by the GNU Public License and may be\n"); printf("copied free of charge. No warrenty is implied.\n\n"); exit(0); break; case 'F': NO_FORK = true; break; case 'H': HISTO = true; break; case 'T': TCPDUMP = true; break; default: Syntax(); exit(1); } } LOGGING = true; /* Do output to syslog */ SetReferenceTime(false); SetStartTime(false); SetSignals(); signal (SIGTERM,HandleSignal); /* Signal Handler */ signal (SIGHUP,HandleSignal); signal (SIGINT,HandleSignal); signal (SIGPIPE,HandleSignal); signal (SIGSEGV,HandleSignal); signal (SIGUSR1,HandleSignal); signal (SIGUSR2,HandleSignal); }
/* ######################################################################### */ static void ParseParam(int argc, char *argv[], struct dynamo_param *param) { // Local variables char cSwitchKey; BOOL bParamIometer = FALSE; BOOL bParamDynamo = FALSE; int count = 0; ifstream devfile; // Walk through the parameter list for( int I = 1; I < argc; I++ ) { // See if the user is requesting syntax help. if ( ( argv[I][0] == '?' ) || ( argv[I][1] == '?' ) ) { Syntax(); return; } // Ensure that the each parameter has a leading switch if ( ( argv[I][0] != '-' ) && ( argv[I][0] != '/' ) ) { Syntax( "Exactly one letter must follow a switch character.\n" "Switch characters are \"-\" and \"/\"." ); return; } if ( strlen( argv[I] ) != 2 ) { Syntax( "Exactly one letter must follow a switch character.\n" "Switch characters are \"-\" and \"/\"." ); return; } // Ensure that each parameter has a value following the switch if( ( I + 1 ) >= argc ) { Syntax("An additional parameter was expected after the last switch."); return; } // Process the parameters based on the switch cSwitchKey = toupper( argv[I][1] ); I++; switch( cSwitchKey ) { case 'I': if ( bParamIometer == TRUE ) { Syntax("Iometer address was specified more than once."); return; } if ( strlen( argv[I] ) >= MAX_NETWORK_NAME ) { Syntax("Iometer address parameter was too long."); return; } strcpy( param->iometer, argv[I] ); bParamIometer = TRUE; break; case 'M': // No check for more then once specification (as we have a default) if ( strlen( argv[I] ) >= MAX_NETWORK_NAME ) { Syntax("Manager network name parameter was too long."); return; } strcpy( param->manager_computer_name, argv[I] ); bParamDynamo = TRUE; break; case 'N': if ( param->manager_name[0] != '\0' ) { Syntax("Manager name was specified more than once."); return; } if ( strlen( argv[I] ) >= MAX_WORKER_NAME ) { Syntax("Manager name parameter was too long."); return; } strcpy( param->manager_name, argv[I] ); break; #if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_NETWARE) || defined(IOMTR_OS_SOLARIS) case 'X': if ( ( strlen( argv[I] ) + strlen( param->manager_exclude_fs ) ) >= MAX_EXCLUDE_FILESYS ) { Syntax("Excluded filesystem list too long."); return; } strcat( param->manager_exclude_fs, argv[I] ); strcat( param->manager_exclude_fs, " " ); break; #endif #if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_SOLARIS) case 'D': if (check_dev(argv[I])) { Syntax("Not a valid device."); return; } if (count < MAX_TARGETS) { strcpy((*param->blkdevlist)[count++], argv[I]); } else { cout << "Too many targets you want to test, skip " << argv[I] << endl; } break; case 'F': char devname[MAX_NAME]; devfile.open(argv[I]); if (!devfile.is_open()) { Syntax("Can not open device file list."); return; } while (!devfile.eof()) { memset(devname, 0, MAX_NAME); devfile.getline(devname, MAX_NAME - 1); if (check_dev(devname)) continue; if (count < MAX_TARGETS) { strcpy((*param->blkdevlist)[count++], devname); } else { cout << "Too many targets you want to test, skip " << devname << endl; } } break; case 'L': do_syslog = TRUE; openlog(NEW_WORKER_EXECUTABLE, 0, LOG_USER); break; #endif #if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_WIN32) || defined(IOMTR_OS_WIN64) case 'C': if (argv[I]) param->cpu_affinity = (unsigned long)atol(argv[I]); break; #endif default: { char tmpary[2] = { cSwitchKey, 0 }; #if defined(IOMTR_OSFAMILY_NETWARE) || defined(IOMTR_OSFAMILY_UNIX) char temp_array[128]; strcpy(temp_array, "Unrecognized switch: "); strcat(temp_array, tmpary); strcat(temp_array, "."); Syntax(temp_array); #elif defined(IOMTR_OSFAMILY_WINDOWS) Syntax("Unrecognized switch: " + (CString)tmpary + "."); #else #warning ===> WARNING: You have to do some coding here to get the port done! #endif } break; } } // Enforce switch combinations if( bParamIometer && !bParamDynamo ) { Syntax( "When specifying the Iometer address, the Manager network name parameter is mandatory." ); } return; }
int main(int argc, char *argv[]) { GenericAgentConfig config = CheckOpts(argc, argv); ReportContext *report_context = OpenReports("executor"); Policy *policy = GenericInitialize("executor", config, report_context); ThisAgentInit(); ExecConfig exec_config = { .scheduled_run = !ONCE, .exec_command = SafeStringDuplicate(""), .mail_server = SafeStringDuplicate(""), .mail_from_address = SafeStringDuplicate(""), .mail_to_address = SafeStringDuplicate(""), .mail_max_lines = 30, .fq_name = VFQNAME, .ip_address = VIPADDRESS, .agent_expireafter = 10080, }; KeepPromises(policy, &exec_config); #ifdef MINGW if (WINSERVICE) { NovaWin_StartExecService(); } else #endif /* MINGW */ { StartServer(policy, &exec_config, report_context); } ReportContextDestroy(report_context); return 0; } /*****************************************************************************/ /* Level 1 */ /*****************************************************************************/ static GenericAgentConfig CheckOpts(int argc, char **argv) { extern char *optarg; int optindex = 0; int c; char ld_library_path[CF_BUFSIZE]; GenericAgentConfig config = GenericAgentDefaultConfig(AGENT_TYPE_EXECUTOR); while ((c = getopt_long(argc, argv, "dvnKIf:D:N:VxL:hFOV1gMW", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': if (optarg && strlen(optarg) < 5) { FatalError(" -f used but argument \"%s\" incorrect", optarg); } SetInputFile(optarg); MINUSF = true; break; case 'd': HardClass("opt_debug"); DEBUG = true; break; case 'K': IGNORELOCK = true; break; case 'D': NewClassesFromString(optarg); break; case 'N': NegateClassesFromString(optarg); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; NO_FORK = true; break; case 'n': DONTDO = true; IGNORELOCK = true; HardClass("opt_dry_run"); break; case 'L': snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg); if (putenv(xstrdup(ld_library_path)) != 0) { } break; case 'W': WINSERVICE = false; break; case 'F': NO_FORK = true; break; case 'O': ONCE = true; break; case 'V': PrintVersionBanner("cf-execd"); exit(0); case 'h': Syntax("cf-execd - cfengine's execution agent", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-execd - cfengine's execution agent", OPTIONS, HINTS, ID); exit(0); case 'x': SelfDiagnostic(); exit(0); default: Syntax("cf-execd - cfengine's execution agent", OPTIONS, HINTS, ID); exit(1); } } if (argv[optind] != NULL) { CfOut(cf_error, "", "Unexpected argument with no preceding option: %s\n", argv[optind]); } return config; } /*****************************************************************************/ static void LoadDefaultSchedule(void) { CfDebug("Loading default schedule...\n"); DeleteItemList(SCHEDULE); SCHEDULE = NULL; AppendItem(&SCHEDULE, "Min00", NULL); AppendItem(&SCHEDULE, "Min05", NULL); AppendItem(&SCHEDULE, "Min10", NULL); AppendItem(&SCHEDULE, "Min15", NULL); AppendItem(&SCHEDULE, "Min20", NULL); AppendItem(&SCHEDULE, "Min25", NULL); AppendItem(&SCHEDULE, "Min30", NULL); AppendItem(&SCHEDULE, "Min35", NULL); AppendItem(&SCHEDULE, "Min40", NULL); AppendItem(&SCHEDULE, "Min45", NULL); AppendItem(&SCHEDULE, "Min50", NULL); AppendItem(&SCHEDULE, "Min55", NULL); }
void get_line_opt( int argc , char *argv[] , line_opt *opt ) { int nopt ; float ftemp ; MRI_IMAGE *im ; time_series *ideal; time_series *ort; char err_note[128]; Boolean ok; char input_filename[THD_MAX_NAME]; /* --- give help if needed --- */ if( argc < 2 || strncmp(argv[1],"-help",4) == 0 ) Syntax(NULL) ; /*----- add to program log -----*/ AFNI_logger (PROGRAM_NAME,argc,argv); /* --- setup opt with defaults --- */ strcpy (opt->prefix_name, ""); /* no prefix name yet */ opt->first_im = 0 ; /* first image to actually use */ opt->max_percent = 0.0; /* --- initialize array of time series data --- */ INIT_TSARR(opt->idts) ; /* --- initialize array of ort time series data --- */ /* 10 Dec 1996 */ INIT_TSARR (opt->ortts); /* --- set defaults in local variables --- */ ideal = NULL ; /* time_series of ideal response vector */ strcpy (input_filename, ""); /* no input file name yet */ /* --- read command line arguments and process them: coding technique is to examine each argv, and if it matches something we expect (e.g., -ideal), process it, then skip to the next loop through ('continue' statements in each strncmp if). Note that the 'while' will increment the argument index (nopt) --- */ nopt = 1 ; do{ #ifdef DEBUG # define DBOPT(str) fprintf(stderr,"at option %s: %s\n",argv[nopt],str) #else # define DBOPT(str) /* nothing */ #endif /* --- -im1 # ==> index (1...) of first image to actually use --- */ if( strncmp(argv[nopt],"-im1",4) == 0 ) { DBOPT("-im1") ; if( ++nopt >= argc ) Syntax("-im1 needs an argument") ; ftemp = strtod( argv[nopt] , NULL ) ; if( ftemp < 1.0 ) { sprintf( err_note , "illegal -im1 value: %f" , ftemp ) ; Syntax(err_note) ; } opt->first_im = (int)(ftemp+0.499) - 1; continue ; } /* --- -ideal file ==> ideal response vector time series --- */ if( strncmp(argv[nopt],"-ideal",5) == 0 ) { DBOPT("-ideal") ; if( ++nopt >= argc ) Syntax("-ideal needs a filename") ; /** July 1995: read a bunch of ideals using [ a b c ... ] format **/ if( ! IS_OPENER(argv[nopt]) ) { /* --- one file --- */ ideal = RWC_read_time_series( argv[nopt] ) ; if( ideal == NULL ) Syntax ("Unable to read ideal time series."); ADDTO_TSARR( opt->idts , ideal ) ; } else { /* --- many files --- */ for( nopt++ ; !IS_CLOSER(argv[nopt]) && nopt<argc ; nopt++ ) { ideal = RWC_read_time_series( argv[nopt] ) ; if( ideal == NULL ) Syntax ("Unable to read ideal time series."); ADDTO_TSARR( opt->idts , ideal ) ; } if( nopt == argc ) Syntax("-ideal never finishes!") ; } continue ; } /*----- -percent p Calculate percentage change from baseline -----*/ if( strncmp(argv[nopt],"-percent",8) == 0 ) { DBOPT("-percent") ; if( ++nopt >= argc ) Syntax("-percent needs an argument") ; ftemp = strtod( argv[nopt] , NULL ) ; if( ftemp <= 0.0 ) { sprintf( err_note , "illegal -percent value: %f" , ftemp ) ; Syntax(err_note) ; } opt->max_percent = ftemp; continue ; } /* --- -ort file ==> ort vector time series --- */ /* 10 Dec 1996 */ if( strncmp(argv[nopt],"-ort",4) == 0 ) { DBOPT("-ort") ; if( ++nopt >= argc ) Syntax("-ort needs a filename") ; /** read a bunch of orts using [ a b c ... ] format **/ if( ! IS_OPENER(argv[nopt]) ) { /* --- one file --- */ ort = RWC_read_time_series( argv[nopt] ) ; if( ort == NULL ) Syntax ("Unable to read ort time series."); ADDTO_TSARR( opt->ortts , ort ) ; } else { /* --- many files --- */ for( nopt++ ; !IS_CLOSER(argv[nopt]) && nopt<argc ; nopt++ ) { ort = RWC_read_time_series( argv[nopt] ) ; if( ort == NULL ) Syntax ("Unable to read ort time series."); ADDTO_TSARR( opt->ortts , ort ) ; } if( nopt == argc ) Syntax("-ort never finishes!") ; } continue ; } /* --- -prefix name ==> prefix name of output file --- */ if( strncmp(argv[nopt], "-prefix", 5) == 0 ){ DBOPT("-prefix") ; if( ++nopt >= argc ) Syntax("-prefix needs a name") ; if( strcmp(opt->prefix_name, "") ) Syntax("Cannot have two prefix output names!" ) ; strcpy (opt->prefix_name, argv[nopt]) ; DBOPT("stored as prefix") ; continue ; } /* --- -input fname ==> file name of input 3d+time data --- */ if( strncmp(argv[nopt], "-input", 5) == 0 ) { DBOPT("-input") ; if( ++nopt >= argc ) Syntax("-input needs a name") ; if( strcmp(input_filename, "") ) Syntax ("Cannot have two input names!" ) ; strcpy (input_filename, argv[nopt] ); /* open 3d data set */ opt->dset = THD_open_one_dataset( argv[nopt] ) ; if( opt->dset == NULL ) { sprintf (err_note, "Unable to open 3d+time data file: %s", argv[nopt]); Syntax (err_note); } continue ; } /* unidentified option */ sprintf( err_note , "Unknown option %s" , argv[nopt] ) ; Syntax(err_note) ; } while( ++nopt < argc ) ; /* loop until all args are read, or we break */ /* --- check for valid user inputs --- */ if (!strcmp(input_filename,"")) Syntax ("No input file name was given."); if( opt->idts->num == 0 ) Syntax("No ideal response vector was defined!") ; if (!strcmp(opt->prefix_name,"")) Syntax ("No prefix name was specified."); /* --- Done! --- */ return ; }
// Input: // prhs[0]: 1xN cell array of 1xL observations // prhs[1]: Sx1 matrix with priors for S states // prhs[2]: SxS matrix with transition probabilities // prhs[3]: SxO matrix with observation probabilities // prhs[4]: Scalar with number of iterations // S: number of states // O: number of observations // Output: // plhs[0]: 1xIteration matrix with log likelihood // plhs[1]: 1xS matrix with re-estimated priors // plhs[2]: SxS matrix with re-estimated transition probabilities // plhs[3]: SxO matrix with re-estimated observation probabilities void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] ) { int S,O,N,Iterations; int i,j; double v1,v2; double r; double *t; //printf("nrhs: %d. nlhs: %d\n",nrhs,nlhs); // Check in/out args if((nrhs!=4 && nrhs!=5) || nlhs!=4 ) { Error(); Syntax(); return; } if(nrhs==4) Iterations=3; else { Iterations = mxGetScalar(prhs[4]); } // Find the number of states and observation and sequences from the PI and B. S = mxGetM(prhs[1]); O = mxGetN(prhs[3]); N = mxGetN(prhs[0]); //printf("N: %d\n",N); // Create the HMM DHMM *hmm=new DHMM(S,O); // Set the starting probabilities t = mxGetPr(prhs[1]); for(i=0;i<S;i++) hmm->StartingStateProbabilities[i]=t[i]; // Set the transition probabilites t = mxGetPr(prhs[2]); for(j=0;j<S;j++) // to state { for(i=0;i<S;i++) // from state { hmm->operator[](i).SetTransitionProbability(j,*t++); } } // Set the observation probabilites t = mxGetPr(prhs[3]); for(j=0;j<O;j++) { for(i=0;i<S;i++) { hmm->operator[](i).SetObservationProbability(j,*t++); } } //hmm->Print(); // Convert the observations to the HMM format. vector<Observation> obs(N); for(i=0;i<N;i++) { mxArray *sequence = mxGetCell(prhs[0],i); int L = mxGetN(sequence); t = mxGetPr(sequence); obs[i].resize(L,0); for(j=0;j<L;j++) { obs[i][j] = (*t++)-1; // Correct for 1-based of matlab, 0-based of C } } // Run the Baum-Welch vector<double> LL = hmm->BaumWelch(obs,Iterations); //hmm->Print(); // Create the return variables plhs[0] = mxCreateDoubleMatrix(1,Iterations,mxREAL); plhs[1] = mxCreateDoubleMatrix(S,1,mxREAL); plhs[2] = mxCreateDoubleMatrix(S,S,mxREAL); plhs[3] = mxCreateDoubleMatrix(S,O,mxREAL); // Get the LL t = mxGetPr(plhs[0]); for(i=0;i<Iterations;i++) t[i] = LL[i]; // Get the starting probabilities t = mxGetPr(plhs[1]); for(i=0;i<S;i++) t[i] = hmm->StartingStateProbabilities[i]; // Get the transition probabilites t = mxGetPr(plhs[2]); for(j=0;j<S;j++) // to state { for(i=0;i<S;i++) // from state { *t++ = hmm->operator[](i).TransitionProbability[j]; } } // Set the observation probabilites t = mxGetPr(plhs[3]); for(j=0;j<O;j++) { for(i=0;i<S;i++) { *t++ = hmm->operator[](i).ObservationProbability[j]; } } delete hmm; }
static GenericAgentConfig CheckOpts(int argc, char **argv) { extern char *optarg; int optindex = 0; int c; GenericAgentConfig config = GenericAgentDefaultConfig(cf_monitor); while ((c = getopt_long(argc, argv, "dvnIf:VSxHTKMFh", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': SetInputFile(optarg); MINUSF = true; break; case 'd': HardClass("opt_debug"); DEBUG = true; NO_FORK = true; break; case 'K': IGNORELOCK = true; break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; NO_FORK = true; break; case 'F': NO_FORK = true; break; case 'H': /* Keep accepting this option for compatibility -- no longer used */ break; case 'T': MonNetworkSnifferEnable(true); break; case 'V': PrintVersionBanner("cf-monitord"); exit(0); case 'h': Syntax("cf-monitord - cfengine's monitoring agent", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-monitord - cfengine's monitoring agent", OPTIONS, HINTS, ID); exit(0); case 'x': SelfDiagnostic(); exit(0); default: Syntax("cf-monitord - cfengine's monitoring agent", OPTIONS, HINTS, ID); exit(1); } } CfDebug("Set debugging\n"); return config; }
GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; char ld_library_path[CF_BUFSIZE]; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_SERVER); while ((c = getopt_long(argc, argv, "dvIKf:D:N:VSxLFMhA", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': if (optarg && (strlen(optarg) < 5)) { CfOut(OUTPUT_LEVEL_ERROR, "", " -f used but argument \"%s\" incorrect", optarg); exit(EXIT_FAILURE); } GenericAgentConfigSetInputFile(config, GetWorkDir(), optarg); MINUSF = true; break; case 'd': config->debug_mode = true; NO_FORK = true; case 'K': IGNORELOCK = true; break; case 'D': config->heap_soft = StringSetFromString(optarg, ','); break; case 'N': config->heap_negated = StringSetFromString(optarg, ','); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; NO_FORK = true; break; case 'F': NO_FORK = true; break; case 'L': CfOut(OUTPUT_LEVEL_VERBOSE, "", "Setting LD_LIBRARY_PATH=%s\n", optarg); snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg); putenv(ld_library_path); break; case 'V': PrintVersion(); exit(0); case 'h': Syntax("cf-serverd", OPTIONS, HINTS, ID, true); exit(0); case 'M': ManPage("cf-serverd - CFEngine's server agent", OPTIONS, HINTS, ID); exit(0); case 'x': CfOut(OUTPUT_LEVEL_ERROR, "", "Self-diagnostic functionality is retired."); exit(0); case 'A': #ifdef HAVE_AVAHI_CLIENT_CLIENT_H #ifdef HAVE_AVAHI_COMMON_ADDRESS_H printf("Generating Avahi configuration file.\n"); if (GenerateAvahiConfig("/etc/avahi/services/cfengine-hub.service") != 0) { exit(1); } cf_popen("/etc/init.d/avahi-daemon restart", "r", true); printf("Avahi configuration file generated successfuly.\n"); exit(0); #else printf("This option can only be used when avahi-daemon and libavahi are installed on the machine.\n"); #endif #endif default: Syntax("cf-serverd", OPTIONS, HINTS, ID, true); exit(1); } } if (!GenericAgentConfigParseArguments(config, argc - optind, argv + optind)) { Log(LOG_LEVEL_ERR, "Too many arguments"); exit(EXIT_FAILURE); } return config; }
static GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; char *sp; int optindex = 0; int c, alpha = false, v6 = false; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_AGENT); /* Because of the MacOS linker we have to call this from each agent individually before Generic Initialize */ POLICY_SERVER[0] = '\0'; while ((c = getopt_long(argc, argv, "rdvnKIf:D:N:Vs:x:MBb:h", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': if (optarg && strlen(optarg) < 5) { FatalError(" -f used but argument \"%s\" incorrect", optarg); } GenericAgentConfigSetInputFile(config, optarg); MINUSF = true; break; case 'b': if (optarg) { config->bundlesequence = SplitStringAsRList(optarg, ','); CBUNDLESEQUENCE_STR = optarg; } break; case 'd': HardClass("opt_debug"); DEBUG = true; break; case 'B': BOOTSTRAP = true; MINUSF = true; GenericAgentConfigSetInputFile(config, "promises.cf"); IGNORELOCK = true; HardClass("bootstrap_mode"); break; case 's': if(IsLoopbackAddress(optarg)) { FatalError("Use a non-loopback address when bootstrapping"); } // temporary assure that network functions are working OpenNetwork(); strncpy(POLICY_SERVER, Hostname2IPString(optarg), CF_BUFSIZE - 1); CloseNetwork(); for (sp = POLICY_SERVER; *sp != '\0'; sp++) { if (isalpha((int)*sp)) { alpha = true; } if (ispunct((int)*sp) && *sp != ':' && *sp != '.') { alpha = true; } if (*sp == ':') { v6 = true; } } if (alpha && !v6) { FatalError ("Error specifying policy server. The policy server's IP address could not be looked up. Please use the IP address instead if there is no error."); } break; case 'K': IGNORELOCK = true; break; case 'D': NewClassesFromString(optarg); break; case 'N': NegateClassesFromString(optarg); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; break; case 'n': DONTDO = true; IGNORELOCK = true; HardClass("opt_dry_run"); break; case 'V': PrintVersionBanner("cf-agent"); exit(0); case 'h': Syntax("cf-agent - cfengine's change agent", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-agent - cfengine's change agent", OPTIONS, HINTS, ID); exit(0); case 'x': CfOut(cf_error, "", "Self-diagnostic functionality is retired"); exit(0); case 'r': SHOWREPORTS = true; break; default: Syntax("cf-agent - cfengine's change agent", OPTIONS, HINTS, ID); exit(1); } } if (argv[optind] != NULL) { CfOut(cf_error, "", "Unexpected argument with no preceding option: %s\n", argv[optind]); FatalError("Aborted"); } CfDebug("Set debugging\n"); return config; }
int main( int argc, char** argv ) { printf("======================================================================\n"); printf("Skin Compiler v%i.%i.%i ("__DATE__") for S60 Platform.\nCopyright (c) 2003-2008 Nokia. All rights reserved.\n", gPlatformMajor, gPlatformMinor, gVersionMinor ); printf("======================================================================\n"); printf("\n"); if( !ParseArguments( argc, argv ) ) { Syntax(); return 1; } try { SDCIIDConstants::Initialize( iidFile ); } catch( CSDCException e ) { e.Print(); printf("\nItem ID extension list is invalid, INITIALIZATION FAILED!\n"); return 3; } printf("Phase 0: Parameter summary.\n"); printf(" Source file: %s\n", sourceFile ); printf(" Skin name: %s\n", skinName ); if( strlen(mbmPath)>0 ) printf(" MBM/MIF list path: %s\n", mbmPath ); if( strlen(sknPath)>0 ) printf(" SKN output path: %s\n", sknPath ); if( strlen(dllPath)>0 ) printf(" System skin output path: %s\n", dllPath ); if( forceSystem ) printf(" Forcing skin type to be SYSTEM\n"); if( forceNormal ) printf(" Forcing skin type to be NORMAL\n"); if( drmEnabled ) printf(" DRM compatibility mode, PKG generation will be altered\n"); CSDCData* data = NULL; bool error = false; try { data = new CSDCData(); printf("\nPhase 1: Input parsing.\n"); printf(" Opening source file %s ...\n", sourceFile ); gInput.Open( sourceFile ); printf(" Parsing file ...\n"); data->SetBmpPath( L"./" ); CSDCReader reader( data ); reader.Parse(); printf(" Completed.\n"); gInput.iLineNumber = -1; if( forceSystem ) { if( data->IsScalable() ) printf("WARNING: Scalable skin, force parameter has no effect.\n"); else data->iSkinType |= 0x1; } if( forceNormal ) { if( data->IsScalable() ) printf("WARNING: Scalable skin, force parameter has no effect.\n"); else if( (data->iSkinType&0x1) != 0 ) data->iSkinType^=0x1; } bool systemSkin = false; printf("NOTE: Skintype: " ); if( data->IsScalable() ) { printf("Scalable "); } else if( (data->iSkinType & 0x1) != 0 ) { printf("System "); systemSkin = true; } else { printf("Normal "); } if( (data->iSkinType & 0x2) != 0 ) { printf("LangOverride="); switch( data->iSkinType & 0xff00 ) { case 0x100: printf("AH "); break; default: printf("Unknown "); break; } printf("Parent=0x%08x 0x%08x", data->iParentPid.iPID2, data->iParentPid.iPID1 ); } printf("\n"); if( systemSkin ) { throw new CSDCException( ESDCContentError, "System skins are no longer supported, please use scalable skin type instead" ); } if( (data->iAHOverridePid.iPID1!=0) || (data->iAHOverridePid.iPID1!=0) ) { printf("NOTE: Associated A&H override is: 0x%08x 0x%08x", data->iAHOverridePid.iPID2, data->iAHOverridePid.iPID1 ); } if( (data->iPid.iPID1==0) && (data->iPid.iPID2==0) ) { GeneratePID( data ); printf("NOTE: Generated package ID for this skin is 0x%08x 0x%08x\n", data->iPid.iPID2, data->iPid.iPID1 ); } printf("\nPhase 2: Output for MBM/MIF generation.\n"); char namebuf[512]; strcpy( namebuf, skinName ); char namebuf2[512]; strcpy( namebuf2, mbmPath ); strcat( namebuf2, skinName ); if( data->IsScalable() ) { strcat( namebuf2, "_MIFList.txt" ); } else { strcat( namebuf2, "_MBMList.txt" ); } printf(" Writing MBM/MIF list for %s to %s ...\n", namebuf, namebuf2 ); CSDCMBMOutput mbmOutput; mbmOutput.Output( data, namebuf, namebuf2 ); printf(" Completed.\n"); printf("\nPhase 3: Output for skin content.\n"); if( systemSkin ) { strcpy( namebuf, dllPath ); strcat( namebuf, skinName ); strcat( namebuf, "_ContentDLL.cpp" ); strcpy( namebuf2, dllPath ); strcat( namebuf2, skinName ); strcat( namebuf2, "_ContentDLL.mmp" ); printf(" Writing CPP and MMP files for %s to %s and %s ...\n", skinName, namebuf, namebuf2 ); CSDCInlOutput inlOutput; inlOutput.Output( data, skinName, namebuf, namebuf2 ); printf(" Completed.\n"); } else { if( strlen(dllPath)>0 ) { printf("WARNING: System skin CPP/MMP path not used.\n"); } printf(" Skipping CPP and MMP file creation (non-system skin).\n"); } strcpy( namebuf, sknPath ); strcat( namebuf, skinName ); strcat( namebuf, ".skn" ); strcpy( namebuf2, skinName ); printf(" Writing SKN file (that uses MBM/MIF %s) to %s ...\n", namebuf2, namebuf ); CSDCBinOutput binOutput; binOutput.Output( data, namebuf2, namebuf, systemSkin ); printf(" Completed.\n"); if( !systemSkin ) { strcpy( namebuf, sknPath ); strcat( namebuf, skinName ); strcat( namebuf, ".pkg" ); if( drmEnabled ) { strcpy( namebuf2, sknPath ); strcat( namebuf2, "datafiles.def" ); } else { strcpy( namebuf2, "" ); } printf(" Writing PKG file for %s to %s ", skinName, namebuf ); if( drmEnabled ) printf("\n and DRM definition file to %s ", namebuf2 ); printf("...\n" ); CSDCPkgOutput pkgOutput; pkgOutput.Output( data, skinName, namebuf, namebuf2 ); printf(" Completed.\n"); } else { printf(" Skipping PKG file creation (system skin).\n"); } } catch( CSDCException e ) { printf("\n----------------------------------------------------------------------\n"); e.Print(); error = true; printf("----------------------------------------------------------------------\n"); } delete data; printf("\n======================================================================\n"); if( error ) { printf("\nAborted, ERRORS ENCOUNTERED!\n"); printf("\n======================================================================\n"); return 2; } printf("\nCompleted successfully.\n"); printf("\n======================================================================\n"); return 0; }
int main(int argc, char *argv[]) { Widget toplevel; Arg arg; Pixmap icon_pixmap = None; XtAppContext app_con; #ifndef NO_I18N char *locale_name = setlocale(LC_ALL,""); XtSetLanguageProc ( NULL, NULL, NULL ); if(!locale_name || 0 == strcmp(locale_name,"C")) { no_locale = True; } else { no_locale = False; } #endif toplevel = XtOpenApplication(&app_con, "XClock", options, XtNumber(options), &argc, argv, NULL, sessionShellWidgetClass, NULL, ZERO); if (argc != 1) Syntax(argv[0]); XtAddCallback(toplevel, XtNdieCallback, die, NULL); XtAddCallback(toplevel, XtNsaveCallback, save, NULL); XtAppAddActions (app_con, xclock_actions, XtNumber(xclock_actions)); /* * This is a hack so that wm_delete_window will do something useful * in this single-window application. */ XtOverrideTranslations(toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()")); XtSetArg(arg, XtNiconPixmap, &icon_pixmap); XtGetValues(toplevel, &arg, ONE); if (icon_pixmap == None) { arg.value = (XtArgVal)XCreateBitmapFromData(XtDisplay(toplevel), XtScreen(toplevel)->root, (char *)clock_bits, clock_width, clock_height); XtSetValues (toplevel, &arg, ONE); } XtSetArg(arg, XtNiconMask, &icon_pixmap); XtGetValues(toplevel, &arg, ONE); if (icon_pixmap == None) { arg.value = (XtArgVal)XCreateBitmapFromData(XtDisplay(toplevel), XtScreen(toplevel)->root, (char *)clock_mask_bits, clock_mask_width, clock_mask_height); XtSetValues (toplevel, &arg, ONE); } XtCreateManagedWidget ("clock", clockWidgetClass, toplevel, NULL, ZERO); XtRealizeWidget (toplevel); wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW", False); (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), &wm_delete_window, 1); #ifdef HAVE_GETPID { pid_t pid = getpid(); XChangeProperty(XtDisplay(toplevel), XtWindow(toplevel), XInternAtom(XtDisplay(toplevel), "_NET_WM_PID", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &pid, 1); } #endif XtAppMainLoop (app_con); exit(0); }
int main(int argc, char* argv[]) { FILE* MapFile=0; FILE* CallsFile=0; FILE* ObjFile=0; FILE* CodeFile=0; FILE* ProtoFile=0; char Line[MAX_STRING]; char Name[MAX_NAME]; char Command[MAX_NAME]; char File[MAX_STRING]; char AddressString[MAX_STRING]; word Address; bool PrependJPs=FALSE; int i; if(argc>1) if(!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) { Syntax(argv[0]); exit(0); } for(i=1; i<argc; i++) { if(!strcmp(argv[i], "--jp")) { PrependJPs=TRUE; } else if(!strcmp(argv[i], "--code") && i+1<argc) { CodeFile=fopen(argv[++i], "w"); } else if((!strcmp(argv[i], "--input") || !strcmp(argv[i], "-i")) && i+1<argc) { if(!strcmp(argv[++i], "-")) { CallsFile=stdin; } else { CallsFile=fopen(argv[i], "r"); } } else if(!strcmp(argv[i], "--sym") && i+1<argc) { MapFile=fopen(argv[++i], "r"); } else if((!strcmp(argv[i], "--obj") || !strcmp(argv[i], "-o")) && i+1<argc) { ObjFile=fopen(argv[++i], "w"); } } if(!CallsFile || !MapFile || !ObjFile) { fprintf(stderr, "You must specify at least a valid input file, symbols file and object file\n"); Syntax(argv[0]); exit(-1); } if(CodeFile) fprintf(stderr, "Will generate a C source with function wrappers.\n"); fprintf(stderr, "Creating list of functions to be mapped...\n"); FunctionsCount=0; while(!feof(CallsFile)) { fgets(Line, MAX_STRING, CallsFile); sscanf(Line, "%s", Command); if(!strcmp(Command, "prototypes")) { sscanf(Line, "%s %s", Command, File); if(ProtoFile) fclose(ProtoFile); if(!(ProtoFile=fopen(File, "r"))) { fprintf(stderr, "No such prototypes file '%s'.\n", File); exit(-1); } } else { sscanf(Line, "%x %s", &Functions[FunctionsCount].ID, Functions[FunctionsCount].Name); Functions[FunctionsCount].Address=0xFFFF; if(ProtoFile) GetPrototype(ProtoFile, &Functions[FunctionsCount]); if(!feof(CallsFile)) FunctionsCount++; } } fprintf(stderr, "Mapping functions...\n"); while(!feof(MapFile)) { fgets(Line, MAX_STRING, MapFile); if(Line[0]!=';') { sscanf(Line, "%s %s", AddressString, Name); sscanf(&AddressString[3], "%x", &Address); if(Name[0]=='_' && AddressString[2]==':') Map(&Name[1], Address); } } fprintf(stderr, "Sorting list...\n"); SortFunctions(); fprintf(stderr, "Generating output...\n\n"); if(CodeFile) { fprintf(CodeFile, "/* Library source generated by funcmap\n (Copyright (c) 2003 Lorenzo J. Lucchini, <*****@*****.**>)\n\n Every library function saves the address to resume userland execution from\n into HL, then loads the system call number into A, and then makes the call\n by means of a RST08 instruction. */\n\n\n"); fprintf(CodeFile, "/* Declarations */\n\n"); for(i=0; i<FunctionsCount; i++) { fprintf(CodeFile, "%s;\n", Functions[i].Prototype); } fprintf(CodeFile, "\n/* Definitions */ \n"); } for(i=0; i<FunctionsCount; i++) { if(Functions[i].Address==0xFFFF) { fprintf(stderr, "Warning: Unmapped call %03d ('%s')\n", Functions[i].ID, Functions[i].Name); } else { if(CodeFile) { fprintf(CodeFile, "\n%s {\n", Functions[i].Prototype); fprintf(CodeFile, " _asm\n pop hl\n ld a,#0x%02x\n rst 0x08\n _endasm;\n", Functions[i].ID); fprintf(CodeFile, "}\n"); } fprintf(stdout, "Call %03d: '%s' at %04x\n", Functions[i].ID, Functions[i].Name, Functions[i].Address); if(PrependJPs) fprintf(ObjFile, "%c", OP_JP); fprintf(ObjFile, "%c%c", Functions[i].Address&0xff, (Functions[i].Address>>8)&0xff); } } fprintf(stdout, "\n"); return 0; }
GenericAgentConfig CheckOpts(int argc, char **argv) { extern char *optarg; char ld_library_path[CF_BUFSIZE]; int optindex = 0; int c; GenericAgentConfig config = GenericAgentDefaultConfig(cf_server); while ((c = getopt_long(argc, argv, "dvIKf:D:N:VSxLFMh", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': if (optarg && (strlen(optarg) < 5)) { FatalError(" -f used but argument \"%s\" incorrect", optarg); } SetInputFile(optarg); MINUSF = true; break; case 'd': DEBUG = true; NO_FORK = true; case 'K': IGNORELOCK = true; break; case 'D': NewClassesFromString(optarg); break; case 'N': NegateClassesFromString(optarg); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; NO_FORK = true; break; case 'F': NO_FORK = true; break; case 'L': CfOut(cf_verbose, "", "Setting LD_LIBRARY_PATH=%s\n", optarg); snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg); putenv(ld_library_path); break; case 'V': PrintVersionBanner("cf-serverd"); exit(0); case 'h': Syntax("cf-serverd - cfengine's server agent", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-serverd - cfengine's server agent", OPTIONS, HINTS, ID); exit(0); case 'x': SelfDiagnostic(); exit(0); default: Syntax("cf-serverd - cfengine's server agent", OPTIONS, HINTS, ID); exit(1); } } if (argv[optind] != NULL) { CfOut(cf_error, "", "Unexpected argument with no preceding option: %s\n", argv[optind]); FatalError("Aborted"); } CfDebug("Set debugging\n"); return config; }
GenericAgentConfig *CheckOpts(EvalContext *ctx, int argc, char **argv) { extern char *optarg; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_COMMON); while ((c = getopt_long(argc, argv, "dvnIf:D:N:VSrxMb:i:p:cg:h", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'c': config->check_runnable = true; break; case 'f': if (optarg && (strlen(optarg) < 5)) { CfOut(OUTPUT_LEVEL_ERROR, "", " -f used but argument \"%s\" incorrect", optarg); exit(EXIT_FAILURE); } GenericAgentConfigSetInputFile(config, optarg); MINUSF = true; break; case 'd': config->debug_mode = true; break; case 'b': if (optarg) { Rlist *bundlesequence = RlistFromSplitString(optarg, ','); GenericAgentConfigSetBundleSequence(config, bundlesequence); RlistDestroy(bundlesequence); CBUNDLESEQUENCE_STR = optarg; // TODO: wtf is this } break; case 'p': if (strcmp("none", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_NONE; } else if (strcmp("cf", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_CF; } else if (strcmp("json", optarg) == 0) { config->agent_specific.common.policy_output_format = GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_JSON; } else { CfOut(OUTPUT_LEVEL_ERROR, "", "Invalid policy output format: '%s'. Possible values are 'none', 'cf', 'json'", optarg); exit(EXIT_FAILURE); } break; case 'K': IGNORELOCK = true; break; case 'D': config->heap_soft = StringSetFromString(optarg, ','); break; case 'N': config->heap_negated = StringSetFromString(optarg, ','); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; break; case 'n': DONTDO = true; IGNORELOCK = true; LOOKUP = true; EvalContextHeapAddHard(ctx, "opt_dry_run"); break; case 'V': PrintVersionBanner("cf-promises"); exit(0); case 'h': Syntax("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID); exit(0); case 'r': SHOWREPORTS = true; break; case 'x': CfOut(OUTPUT_LEVEL_ERROR, "", "Self-diagnostic functionality is retired."); exit(0); default: Syntax("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID); exit(1); } } if (argv[optind] != NULL) { CfOut(OUTPUT_LEVEL_ERROR, "", "Unexpected argument: %s\n", argv[optind]); } CfDebug("Set debugging\n"); return config; }
GenericAgentConfig *CheckOpts(int argc, char **argv) { extern char *optarg; char ld_library_path[CF_BUFSIZE]; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_SERVER); while ((c = getopt_long(argc, argv, "dvIKf:D:N:VSxLFMhA", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': if (optarg && (strlen(optarg) < 5)) { FatalError(" -f used but argument \"%s\" incorrect", optarg); } GenericAgentConfigSetInputFile(config, optarg); MINUSF = true; break; case 'd': DEBUG = true; NO_FORK = true; case 'K': IGNORELOCK = true; break; case 'D': NewClassesFromString(optarg); break; case 'N': NegateClassesFromString(optarg); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; NO_FORK = true; break; case 'F': NO_FORK = true; break; case 'L': CfOut(cf_verbose, "", "Setting LD_LIBRARY_PATH=%s\n", optarg); snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg); putenv(ld_library_path); break; case 'V': PrintVersionBanner("cf-serverd"); exit(0); case 'h': Syntax("cf-serverd - cfengine's server agent", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-serverd - cfengine's server agent", OPTIONS, HINTS, ID); exit(0); case 'x': CfOut(cf_error, "", "Self-diagnostic functionality is retired."); exit(0); case 'A': #ifdef HAVE_AVAHI_CLIENT_CLIENT_H #ifdef HAVE_AVAHI_COMMON_ADDRESS_H printf("Generating Avahi configuration file.\n"); if (GenerateAvahiConfig("/etc/avahi/services/cfengine-hub.service") != 0) { exit(1); } cf_popen("/etc/init.d/avahi-daemon restart", "r"); printf("Avahi configuration file generated successfuly.\n"); exit(0); #else printf("This option can only be used when avahi-daemon and libavahi are installed on the machine.\n"); #endif #endif default: Syntax("cf-serverd - cfengine's server agent", OPTIONS, HINTS, ID); exit(1); } } if (argv[optind] != NULL) { CfOut(cf_error, "", "Unexpected argument with no preceding option: %s\n", argv[optind]); FatalError("Aborted"); } CfDebug("Set debugging\n"); return config; }
void CheckOpts(int argc,char **argv) { extern char *optarg; char arg[CF_BUFSIZE],*sp; int optindex = 0; int c,alpha = false,v6 = false; /* Because of the MacOS linker we have to call this from each agent individually before Generic Initialize */ POLICY_SERVER[0] = '\0'; while ((c=getopt_long(argc,argv,"rd:vnKIf:D:N:Vs:x:MBb:",OPTIONS,&optindex)) != EOF) { switch ((char) c) { case 'f': if (optarg == NULL) { FatalError(" -f used but no argument"); } if (optarg && strlen(optarg) < 5) { snprintf(arg,CF_MAXVARSIZE," -f used but argument \"%s\" incorrect",optarg); FatalError(arg); } strncpy(VINPUTFILE,optarg,CF_BUFSIZE-1); MINUSF = true; break; case 'b': if (optarg) { CBUNDLESEQUENCE = SplitStringAsRList(optarg,','); CBUNDLESEQUENCE_STR = optarg; } break; case 'd': NewClass("opt_debug"); switch ((optarg==NULL) ? '3' : *optarg) { case '1': D1 = true; DEBUG = true; break; case '2': D2 = true; DEBUG = true; break; default: DEBUG = true; break; } break; case 'B': BOOTSTRAP = true; MINUSF = true; IGNORELOCK = true; NewClass("bootstrap_mode"); break; case 's': // temporary assure that network functions are working OpenNetwork(); strncpy(POLICY_SERVER,Hostname2IPString(optarg),CF_BUFSIZE-1); CloseNetwork(); for (sp = POLICY_SERVER; *sp != '\0'; sp++) { if (isalpha(*sp)) { alpha = true; } if (ispunct(*sp) && *sp != ':' && *sp != '.') { alpha = true; } if (*sp == ':') { v6 = true; } } if (alpha && !v6) { FatalError("Error specifying policy server. The policy server's IP address could not be looked up. Please use the IP address instead if there is no error."); } break; case 'K': IGNORELOCK = true; break; case 'D': NewClassesFromString(optarg); break; case 'N': NegateClassesFromString(optarg,&VNEGHEAP); break; case 'I': INFORM = true; break; case 'v': VERBOSE = true; break; case 'n': DONTDO = true; IGNORELOCK = true; NewClass("opt_dry_run"); break; case 'V': PrintVersionBanner("cf-agent"); exit(0); case 'h': Syntax("cf-agent - cfengine's change agent",OPTIONS,HINTS,ID); exit(0); case 'M': ManPage("cf-agent - cfengine's change agent",OPTIONS,HINTS,ID); exit(0); case 'x': AgentDiagnostic(optarg); exit(0); case 'r': SHOWREPORTS = true; break; default: Syntax("cf-agent - cfengine's change agent",OPTIONS,HINTS,ID); exit(1); } } if (argv[optind] != NULL) { CfOut(cf_error,"","Unexpected argument with no preceding option: %s\n",argv[optind]); FatalError("Aborted"); } Debug("Set debugging\n"); }
int main(int argc, char *argv[]) { Visual visual; XSetWindowAttributes xswa; int i; char *displayname = NULL; Display *dpy; Colormap cmap; enum e_action action = doDefault; unsigned long mask; int screen; int x, y, width, height; char *geom = NULL; int geom_result; int display_width, display_height; char *solidcolor = NULL; XColor cdef; ProgramName = argv[0]; for (i = 1; i < argc; i++) { char *arg = argv[i]; if (arg[0] == '-') { if (isabbreviation ("-display", arg, 2)) { if (++i >= argc) Syntax (); displayname = argv[i]; continue; } else if (isabbreviation ("-geometry", arg, 2)) { if (++i >= argc) Syntax (); geom = argv[i]; continue; } else if (isabbreviation ("-black", arg, 2)) { action = doBlack; continue; } else if (isabbreviation ("-white", arg, 2)) { action = doWhite; continue; } else if (isabbreviation ("-solid", arg, 2)) { if (++i >= argc) Syntax (); solidcolor = argv[i]; action = doSolid; continue; } else if (isabbreviation ("-none", arg, 2)) { action = doNone; continue; } else if (isabbreviation ("-root", arg, 2)) { action = doRoot; continue; } else Syntax (); } else if (arg[0] == '=') /* obsolete */ geom = arg; else Syntax (); } if ((dpy = XOpenDisplay(displayname)) == NULL) { fprintf (stderr, "%s: unable to open display '%s'\n", ProgramName, XDisplayName (displayname)); exit (1); } if (action == doDefault) { char *def; if ((def = XGetDefault (dpy, ProgramName, "Solid")) != NULL) { solidcolor = strdup (def); if (solidcolor == NULL) { fprintf (stderr, "%s: unable to allocate memory for string.\n", ProgramName); exit (1); } action = doSolid; } else { struct s_pair *pp; for (pp = pair_table; pp->resource_name != NULL; pp++) { def = XGetDefault (dpy, ProgramName, pp->resource_name); if (def && parse_boolean_option (def) == 1) { action = pp->action; } } } } if (geom == NULL) geom = XGetDefault (dpy, ProgramName, "Geometry"); screen = DefaultScreen (dpy); display_width = DisplayWidth (dpy, screen); display_height = DisplayHeight (dpy, screen); x = y = 0; width = display_width; height = display_height; if (DisplayCells (dpy, screen) <= 2 && action == doSolid) { if (strcmp (solidcolor, "black") == 0) action = doBlack; else if (strcmp (solidcolor, "white") == 0) action = doWhite; else { fprintf (stderr, "%s: can't use colors on a monochrome display.\n", ProgramName); action = doNone; } } if (geom) geom_result = XParseGeometry (geom, &x, &y, (unsigned int *)&width, (unsigned int *)&height); else geom_result = NoValue; /* * For parsing geometry, we want to have the following * * = (0,0) for (display_width,display_height) * =WxH+X+Y (X,Y) for (W,H) * =WxH-X-Y (display_width-W-X,display_height-H-Y) for (W,H) * =+X+Y (X,Y) for (display_width-X,display_height-Y) * =WxH (0,0) for (W,H) * =-X-Y (0,0) for (display_width-X,display_height-Y) * * If we let any missing values be taken from (0,0) for * (display_width,display_height) we just have to deal with the * negative offsets. */ if (geom_result & XNegative) { if (geom_result & WidthValue) { x = display_width - width + x; } else { width = display_width + x; x = 0; } } if (geom_result & YNegative) { if (geom_result & HeightValue) { y = display_height - height + y; } else { height = display_height + y; y = 0; } } mask = 0; switch (action) { case doBlack: xswa.background_pixel = BlackPixel (dpy, screen); mask |= CWBackPixel; break; case doWhite: xswa.background_pixel = WhitePixel (dpy, screen); mask |= CWBackPixel; break; case doSolid: cmap = DefaultColormap (dpy, screen); if (XParseColor (dpy, cmap, solidcolor, &cdef) && XAllocColor (dpy, cmap, &cdef)) { xswa.background_pixel = cdef.pixel; mask |= CWBackPixel; } else { fprintf (stderr,"%s: unable to allocate color '%s'.\n", ProgramName, solidcolor); action = doNone; } break; case doDefault: case doNone: xswa.background_pixmap = None; mask |= CWBackPixmap; break; case doRoot: xswa.background_pixmap = ParentRelative; mask |= CWBackPixmap; break; } xswa.override_redirect = True; xswa.backing_store = NotUseful; xswa.save_under = False; mask |= (CWOverrideRedirect | CWBackingStore | CWSaveUnder); visual.visualid = CopyFromParent; win = XCreateWindow(dpy, DefaultRootWindow(dpy), x, y, width, height, 0, DefaultDepth(dpy, screen), InputOutput, &visual, mask, &xswa); /* * at some point, we really ought to go walk the tree and turn off * backing store; or do a ClearArea generating exposures on all windows */ XMapWindow (dpy, win); /* the following will free the color that we might have allocateded */ XCloseDisplay (dpy); exit (0); }
int main(int argc,char **argv) { // XtAppContext app_con; // Widget toplevel, paned, clear, print, quit, text; Arg args[1]; ///////////////////////////////////// // variables added for paradyn integration int ok, fd; ///////////////////////////////////// toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO, &argc, argv, fallback_resources, NULL, ZERO); /* * Check to see that all arguments were processed, and if not then * report an error and exit. */ if (argc != 1) Syntax(app_con, argv[0]); ////////////////////////////////////// // call visi_Init: step (1) from README file if((fd = visi_Init()) < 0){ exit(-1); } ////////////////////////////////////// ////////////////////////////////////// // register event callbacks: step (2) from README file ok = visi_RegistrationCallback(ADDMETRICSRESOURCES,fd_input2); ok = visi_RegistrationCallback(DATAVALUES,fd_input); ok = visi_RegistrationCallback(FOLD,fd_input); ok = visi_RegistrationCallback(INVALIDMETRICSRESOURCES,fd_input); ////////////////////////////////////// paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel, NULL, ZERO); clear = XtCreateManagedWidget("clear", commandWidgetClass, paned, NULL, ZERO); print = XtCreateManagedWidget("print", commandWidgetClass, paned, NULL, ZERO); quit = XtCreateManagedWidget("quit", commandWidgetClass, paned, NULL, ZERO); ////////////////////////////////////// // this is for an upcall to Paradyn: step (3a) from README getMR = XtCreateManagedWidget("Get Metric Resource",commandWidgetClass, paned,NULL,ZERO); stopMR = XtCreateManagedWidget("Stop Metric Resource",commandWidgetClass, paned,NULL,ZERO); phaseN = XtCreateManagedWidget("Name a Phase",commandWidgetClass, paned,NULL,ZERO); ////////////////////////////////////// XtSetArg(args[0], XtNstring, "This is a test.\n"); text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned, args, ONE); XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text); XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text); XtAddCallback(quit, XtNcallback, QuitProgram, (XtPointer) app_con); /////////////////////////////////////// // Add callbacks for upcalls to Paradyn: step (3b) from README XtAddCallback(getMR, XtNcallback, GetMetsResCallback, (XtPointer) app_con); XtAddCallback(stopMR, XtNcallback, StopMetsResCallback, (XtPointer) app_con); XtAddCallback(phaseN, XtNcallback, PName, (XtPointer) app_con); ////////////////////////////////////// ////////////////////////////////////// // register visi_callback routine as callback on events assoc. w/ file desc // step (4) from README file XtAppAddInput(app_con,fd,(XtPointer) XtInputReadMask, (XtInputCallbackProc) visi_callback, text); ////////////////////////////////////// XtRealizeWidget(toplevel); XtAppMainLoop(app_con); }
static GenericAgentConfig CheckOpts(int argc, char **argv) { extern char *optarg; int optindex = 0; int c; GenericAgentConfig config = GenericAgentDefaultConfig(AGENT_TYPE_RUNAGENT); DEFINECLASSES[0] = '\0'; SENDCLASSES[0] = '\0'; while ((c = getopt_long(argc, argv, "t:q:db:vnKhIif:D:VSxo:s:MH:", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': SetInputFile(optarg); MINUSF = true; break; case 'b': BACKGROUND = true; if (optarg) { MAXCHILD = atoi(optarg); } break; case 'd': HardClass("opt_debug"); DEBUG = true; break; case 'q': if (optarg == NULL) { strcpy(MENU, "delta"); } else { strncpy(MENU, optarg, CF_MAXVARSIZE); } break; case 'K': IGNORELOCK = true; break; case 's': strncpy(SENDCLASSES, optarg, CF_MAXVARSIZE); if (strlen(optarg) > CF_MAXVARSIZE) { FatalError("Argument too long\n"); } break; case 'D': strncpy(DEFINECLASSES, optarg, CF_MAXVARSIZE); if (strlen(optarg) > CF_MAXVARSIZE) { FatalError("Argument too long\n"); } break; case 'H': HOSTLIST = SplitStringAsRList(optarg, ','); break; case 'o': strncpy(REMOTE_AGENT_OPTIONS, optarg, CF_MAXVARSIZE); break; case 'I': INFORM = true; break; case 'i': INTERACTIVE = true; break; case 'v': VERBOSE = true; break; case 'n': DONTDO = true; IGNORELOCK = true; HardClass("opt_dry_run"); break; case 't': CONNTIMEOUT = atoi(optarg); break; case 'V': PrintVersionBanner("cf-runagent"); exit(0); case 'h': Syntax("cf-runagent - Run agent", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-runagent - Run agent", OPTIONS, HINTS, ID); exit(0); case 'x': SelfDiagnostic(); exit(0); default: Syntax("cf-runagent - Run agent", OPTIONS, HINTS, ID); exit(1); } } CfDebug("Set debugging\n"); return config; }
static GenericAgentConfig *CheckOpts(EvalContext *ctx, int argc, char **argv) { extern char *optarg; int optindex = 0; int c; GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_RUNAGENT); DEFINECLASSES[0] = '\0'; SENDCLASSES[0] = '\0'; while ((c = getopt_long(argc, argv, "t:q:db:vnKhIif:D:VSxo:s:MH:", OPTIONS, &optindex)) != EOF) { switch ((char) c) { case 'f': GenericAgentConfigSetInputFile(config, optarg); MINUSF = true; break; case 'b': BACKGROUND = true; if (optarg) { MAXCHILD = atoi(optarg); } break; case 'd': config->debug_mode = true; break; case 'K': IGNORELOCK = true; break; case 's': strncpy(SENDCLASSES, optarg, CF_MAXVARSIZE); if (strlen(optarg) > CF_MAXVARSIZE) { CfOut(OUTPUT_LEVEL_ERROR, "", "Argument too long\n"); exit(EXIT_FAILURE); } break; case 'D': strncpy(DEFINECLASSES, optarg, CF_MAXVARSIZE); if (strlen(optarg) > CF_MAXVARSIZE) { CfOut(OUTPUT_LEVEL_ERROR, "", "Argument too long\n"); exit(EXIT_FAILURE); } break; case 'H': HOSTLIST = RlistFromSplitString(optarg, ','); break; case 'o': strncpy(REMOTE_AGENT_OPTIONS, optarg, CF_MAXVARSIZE); break; case 'I': INFORM = true; break; case 'i': INTERACTIVE = true; break; case 'v': VERBOSE = true; break; case 'n': DONTDO = true; IGNORELOCK = true; EvalContextHeapAddHard(ctx, "opt_dry_run"); break; case 't': CONNTIMEOUT = atoi(optarg); break; case 'V': PrintVersion(); exit(0); case 'h': Syntax("cf-runagent - Run agent", OPTIONS, HINTS, ID); exit(0); case 'M': ManPage("cf-runagent - Run agent", OPTIONS, HINTS, ID); exit(0); case 'x': CfOut(OUTPUT_LEVEL_ERROR, "", "Self-diagnostic functionality is retired."); exit(0); default: Syntax("cf-runagent - Run agent", OPTIONS, HINTS, ID); exit(1); } } CfDebug("Set debugging\n"); return config; }
void F3D_initialize_user_data ( int Argc, char * Argv[], Boolean * verbose, Boolean * nsize, int * zfirst, int * zlast, int * tfirst, int * tlast, char * input_filename, char * prefix_filename ) { const int BIGNUMBER = 10000; int nopt; float ftemp; if (Argc < 2) Syntax(); /* --- set default values --- */ *verbose = FALSE; *nsize = FALSE; *zfirst = 1; *zlast = BIGNUMBER; *tfirst = 1; *tlast = BIGNUMBER; strcpy(input_filename, ""); strcpy(prefix_filename, ""); /* --- scan options --- */ nopt = 1 ; while ( nopt < Argc && Argv[nopt][0] == '-' ) { /* --- help option --- */ if ( strncmp(Argv[nopt],"-help",4) == 0 ) Syntax() ; /* --- verbose option --- */ if ( strncmp(Argv[nopt],"-v",2) == 0 ) { *verbose = TRUE; nopt++ ; continue; } #if 0 /* --- nsize option --- */ if ( strncmp(Argv[nopt],"-nsize",4) == 0 ) { *nsize = TRUE; nopt++ ; continue; } #endif /*-- -times n --*/ if( strncmp(Argv[nopt],"-times",4) == 0 ){ if( ++nopt >= Argc ) FatalError("-times needs an argument") ; ftemp = strtod( Argv[nopt] , NULL ) ; if( ftemp >= 1.0 ) ntimes = (int) ftemp ; nopt++ ; continue ; } #if 0 /* --- zfirst option --- */ if ( strncmp(Argv[nopt],"-zfirst",4) == 0 ) { if( ++nopt >= Argc ) FatalError("-zfirst needs an argument") ; ftemp = strtod( Argv[nopt] , NULL ) ; *zfirst = (int) ftemp ; nopt++ ; continue ; } /* --- zlast option --- */ if ( strncmp(Argv[nopt],"-zlast",4) == 0 ) { if( ++nopt >= Argc ) FatalError("-zlast needs an argument") ; ftemp = strtod( Argv[nopt] , NULL ) ; *zlast = (int) ftemp ; nopt++ ; continue ; } /* --- tfirst option --- */ if ( strncmp(Argv[nopt],"-tfirst",4) == 0 ) { if( ++nopt >= Argc ) FatalError("-tfirst needs an argument") ; ftemp = strtod( Argv[nopt] , NULL ) ; *tfirst = (int) ftemp ; nopt++ ; continue ; } /* --- tlast option --- */ if ( strncmp(Argv[nopt],"-tlast",4) == 0 ) { if( ++nopt >= Argc ) FatalError("-tlast needs an argument") ; ftemp = strtod( Argv[nopt] , NULL ) ; *tlast = (int) ftemp ; nopt++ ; continue ; } #endif if( strncmp(Argv[nopt],"-shm",4) == 0 ){ use_shm = 1 ; nopt++ ; continue ; } if( strncmp(Argv[nopt],"-tcp",4) == 0 ){ use_shm = 0 ; nopt++ ; continue ; } if( strncmp(Argv[nopt],"-child",4) == 0 ){ use_child = 1 ; nopt++ ; continue ; } if( strncmp(Argv[nopt],"-3T",4) == 0 ){ if( ++nopt >= Argc ) FatalError("-3T needs a filename") ; fname_3T = Argv[nopt] ; use_3T = 1 ; nopt++ ; continue ; } if( strncmp(Argv[nopt],"-delay",4) == 0 ){ if ( ++nopt >= Argc ) FatalError("-delay needs a number") ; ftemp = strtod( Argv[nopt] , NULL ) ; if( ftemp >= 0.0 ) delay = (int) ftemp ; nopt++ ; continue ; } if( strncmp(Argv[nopt],"-host",4) == 0 ){ if ( ++nopt >= Argc ) FatalError("-host needs a cpu name") ; strcpy( host , Argv[nopt] ) ; nopt++ ; continue ; } /* --- input file name --- */ if ( strncmp(Argv[nopt],"-input",4) == 0 ) { if ( ++nopt >= Argc ) FatalError("-input needs a name") ; strcpy ( input_filename , Argv[nopt] ) ; nopt++ ; continue ; } #if 0 /* --- prefix name --- */ if ( strncmp(Argv[nopt],"-prefix",4) == 0 ) { if ( ++nopt >= Argc ) FatalError("-prefix needs a name") ; strcpy ( prefix_filename , Argv[nopt] ) ; nopt++ ; continue ; } #endif /* --- exception --- */ fprintf(stderr,"Don't understand argument %s\n",Argv[nopt]) ; FatalError ("Illegal input"); } /* nopt */ /* --- check for valid inputs --- */ #if 0 if (*zfirst > *zlast) FatalError ("Cannot have zfirst > zlast"); if (*tfirst > *tlast) FatalError ("Cannot have tfirst > tlast"); if (!strcmp(prefix_filename,"")) FatalError ("Must specify prefix file name."); #endif if (!strcmp(input_filename,"")) FatalError ("Must specify input file name. "); if( strcmp(host,"localhost") != 0 && use_shm ){ printf("EPsim: must use TCP/IP for host %s\n",host) ; use_shm = 0 ; } if( use_child && use_3T ) FatalError("Can't use -child and -3T together!") ; return; }
void CheckOptsAndInit(int argc,char **argv) { extern char *optarg; int optindex = 0; char ld_library_path[CF_BUFSIZE]; int c,seed; unsigned char s[16]; ld_library_path[0] = '\0'; Banner("Check options"); NOSPLAY = false; sprintf(VPREFIX, "cfexecd"); openlog(VPREFIX,LOG_PID|LOG_NOWAIT|LOG_ODELAY,LOG_DAEMON); while ((c=getopt_long(argc,argv,"L:d:vhpqFV1g",CFDOPTIONS,&optindex)) != EOF) { switch ((char) c) { case 'd': switch ((optarg==NULL)?3:*optarg) { case '1': D1 = true; break; case '2': D2 = true; break; default: DEBUG = true; break; } NO_FORK = true; VERBOSE = true; printf("cfexecd Debug mode: running in foreground\n"); break; case 'v': VERBOSE = true; break; case 'V': printf("GNU %s-%s daemon\n%s\n",PACKAGE,VERSION,COPYRIGHT); printf("This program is covered by the GNU Public License and may be\n"); printf("copied free of charge. No warrenty is implied.\n\n"); exit(0); break; case 'q': NOSPLAY = true; break; case 'p': PARSEONLY = true; break; case 'g': NO_FORK = true; break; case 'L': snprintf(ld_library_path,CF_BUFSIZE-1,"LD_LIBRARY_PATH=%s",optarg); if (putenv(strdup(ld_library_path)) != 0) { } break; case 'F': case '1': ONCE = true; NO_FORK = true; break; case 'h': Syntax(); exit(1); break; /* never reached.... */ default: Syntax(); exit(1); } } LOGGING = true; /* Do output to syslog */ /* XXX Initialize workdir for non privileged users */ strcpy(CFWORKDIR,WORKDIR); #ifndef NT if (getuid() > 0) { char *homedir; if ((homedir = getenv("HOME")) != NULL) { strcpy(CFWORKDIR,homedir); strcat(CFWORKDIR,"/.cfagent"); } } #endif snprintf(VBUFF,CF_BUFSIZE,"%s/inputs/update.conf",CFWORKDIR); MakeDirectoriesFor(VBUFF,'y'); snprintf(VBUFF,CF_BUFSIZE,"%s/bin/cfagent -D from_cfexecd",CFWORKDIR); MakeDirectoriesFor(VBUFF,'y'); snprintf(VBUFF,CF_BUFSIZE,"%s/outputs/spooled_reports",CFWORKDIR); MakeDirectoriesFor(VBUFF,'y'); snprintf(VBUFF,CF_BUFSIZE,"%s/inputs",CFWORKDIR); chmod(VBUFF,0700); snprintf(VBUFF,CF_BUFSIZE,"%s/outputs",CFWORKDIR); chmod(VBUFF,0700); strncpy(VLOCKDIR,CFWORKDIR,CF_BUFSIZE-1); strncpy(VLOGDIR,CFWORKDIR,CF_BUFSIZE-1); VCANONICALFILE = strdup(CanonifyName(VINPUTFILE)); GetCfStuff(); MAILTO[0] = '\0'; MAILFROM[0] = '\0'; VIPADDRESS[0] = '\0'; VMAILSERVER[0] = '\0'; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); CheckWorkDirectories(); RandomSeed(); RAND_bytes(s,16); s[15] = '\0'; seed = ElfHash(s); srand48((long)seed); }
int main(int argc, char *argv[]) { int i, ret; char *displayname = NULL; Display *dpy; float gam = -1., rgam = -1., ggam = -1., bgam = -1.; XF86VidModeGamma gamma; Bool quiet = False; int screen = -1; ProgramName = argv[0]; for (i = 1; i < argc; i++) { char *arg = argv[i]; if (arg[0] == '-') { if (isabbreviation ("-display", arg, 1)) { if (++i >= argc) Syntax ("-display requires an argument"); displayname = argv[i]; continue; } else if (isabbreviation ("-quiet", arg, 1)) { quiet = True; continue; } else if (isabbreviation ("-version", arg, 1)) { puts(PACKAGE_STRING); exit(0); } else if (isabbreviation ("-screen", arg, 1)) { if (++i >= argc) Syntax ("-screen requires an argument"); screen = atoi(argv[i]); continue; } else if (isabbreviation ("-gamma", arg, 2)) { if (++i >= argc) Syntax ("-gamma requires an argument"); if ((rgam >= 0.) || (ggam >= 0.) || (bgam >= 0.)) Syntax ("-gamma cannot be used with -rgamma, -ggamma, or -bgamma"); gam = (float)atof(argv[i]); if ((gam < GAMMA_MIN) || (gam > GAMMA_MAX)) { fprintf(stderr, "Gamma values must be between %6.3f and %6.3f\n", GAMMA_MIN, GAMMA_MAX); exit(1); } continue; } else if (isabbreviation ("-rgamma", arg, 2)) { if (++i >= argc) Syntax ("-rgamma requires an argument"); if (gam >= 0.) Syntax ("cannot set both -gamma and -rgamma"); rgam = (float)atof(argv[i]); if ((rgam < GAMMA_MIN) || (rgam > GAMMA_MAX)) { fprintf(stderr, "Gamma values must be between %6.3f and %6.3f\n", GAMMA_MIN, GAMMA_MAX); exit(1); } continue; } else if (isabbreviation ("-ggamma", arg, 2)) { if (++i >= argc) Syntax ("-ggamma requires an argument"); if (gam >= 0.) Syntax ("cannot set both -gamma and -ggamma"); ggam = (float)atof(argv[i]); if ((ggam < GAMMA_MIN) || (ggam > GAMMA_MAX)) { fprintf(stderr, "Gamma values must be between %6.3f and %6.3f\n", GAMMA_MIN, GAMMA_MAX); exit(1); } continue; } else if (isabbreviation ("-bgamma", arg, 2)) { if (++i >= argc) Syntax ("-bgamma requires an argument"); if (gam >= 0.) Syntax ("cannot set both -gamma and -bgamma"); bgam = (float)atof(argv[i]); if ((bgam < GAMMA_MIN) || (bgam > GAMMA_MAX)) { fprintf(stderr, "Gamma values must be between %6.3f and %6.3f\n", GAMMA_MIN, GAMMA_MAX); exit(1); } continue; } else { if (!isabbreviation ("-help", arg, 1)) fprintf (stderr, "%s: unrecognized argument %s\n\n", ProgramName, arg); Syntax (NULL); } } else { fprintf (stderr, "%s: unrecognized argument %s\n\n", ProgramName, arg); Syntax (NULL); } } if ((dpy = XOpenDisplay(displayname)) == NULL) { fprintf (stderr, "%s: unable to open display '%s'\n", ProgramName, XDisplayName (displayname)); exit(1); } else if (screen == -1) screen = DefaultScreen(dpy); if (!XF86VidModeQueryVersion(dpy, &MajorVersion, &MinorVersion)) { fprintf(stderr, "Unable to query video extension version\n"); exit(2); } if (!XF86VidModeQueryExtension(dpy, &EventBase, &ErrorBase)) { fprintf(stderr, "Unable to query video extension information\n"); exit(2); } /* Fail if the extension version in the server is too old */ if (MajorVersion < MINMAJOR || (MajorVersion == MINMAJOR && MinorVersion < MINMINOR)) { fprintf(stderr, "Xserver is running an old XFree86-VidModeExtension version" " (%d.%d)\n", MajorVersion, MinorVersion); fprintf(stderr, "Minimum required version is %d.%d\n", MINMAJOR, MINMINOR); exit(2); } if (!XF86VidModeGetGamma(dpy, screen, &gamma)) { fprintf(stderr, "Unable to query gamma correction\n"); XCloseDisplay (dpy); exit (2); } else if (!quiet) fprintf(stderr, "-> Red %6.3f, Green %6.3f, Blue %6.3f\n", gamma.red, gamma.green, gamma.blue); ret = 0; if (gam >= 0.) { gamma.red = gam; gamma.green = gam; gamma.blue = gam; if (!XF86VidModeSetGamma(dpy, screen, &gamma)) { fprintf(stderr, "Unable to set gamma correction\n"); ret = 2; } else { if (!XF86VidModeGetGamma(dpy, screen, &gamma)) { fprintf(stderr, "Unable to query gamma correction\n"); ret = 2; } else if (!quiet) fprintf(stderr, "<- Red %6.3f, Green %6.3f, Blue %6.3f\n", gamma.red, gamma.green, gamma.blue); } } else if ((rgam >= 0.) || (ggam >= 0.) || (bgam >= 0.)) { if (rgam >= 0.) gamma.red = rgam; if (ggam >= 0.) gamma.green = ggam; if (bgam >= 0.) gamma.blue = bgam; if (!XF86VidModeSetGamma(dpy, screen, &gamma)) { fprintf(stderr, "Unable to set gamma correction\n"); ret = 2; } else { if (!XF86VidModeGetGamma(dpy, screen, &gamma)) { fprintf(stderr, "Unable to query gamma correction\n"); ret = 2; } else if (!quiet) fprintf(stderr, "<- Red %6.3f, Green %6.3f, Blue %6.3f\n", gamma.red, gamma.green, gamma.blue); } } XCloseDisplay (dpy); exit (ret); }
void CheckOpts(int argc,char **argv) { extern char *optarg; int optindex = 0; int c; /* XXX Initialize workdir for non privileged users */ strcpy(CFWORKDIR,WORKDIR); FLNAME[0] = '\0'; ERASE[0] = '\0'; VERBOSE = false; if (geteuid() > 0) { char *homedir; if ((homedir = getenv("HOME")) != NULL) { strcpy(CFWORKDIR,homedir); strcat(CFWORKDIR,"/.cfagent"); } } snprintf(FILENAME,CF_BUFSIZE,"%s/state/%s",CFWORKDIR,CF_AVDB_FILE); while ((c=getopt_long(argc,argv,"Thtf:o:rsenNEv:",GRAPHOPTIONS,&optindex)) != EOF) { switch ((char) c) { case 'E': strncpy(ERASE,optarg,CF_BUFSIZE-1); break; case 't': TITLES = true; break; case 'f': strcpy(FILENAME,optarg); break; case 'o': strcpy(FLNAME,optarg); Verbose("Setting output directory to s\n",FLNAME); break; case 'T': TIMESTAMPS = true; break; case 'v': VERBOSE = true; break; case 'r': HIRES = true; break; case 's': SEPARATE = true; break; case 'e': ERRORBARS = false; break; case 'n': NOSCALING = true; break; case 'N': NOWOPT = true; break; default: Syntax(); exit(1); } } }