示例#1
0
extern int
main(int argc, char* argv[]) {
    UErrorCode errorCode = U_ZERO_ERROR;
    UBool didSomething = FALSE;
    
    /* preset then read command line options */
    argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);

    /* error handling, printing usage message */
    if(argc<0) {
        fprintf(stderr,
            "error in command line argument \"%s\"\n",
            argv[-argc]);
    }
    if( options[0].doesOccur || options[1].doesOccur) {
      fprintf(stderr, "%s: Output information about the current ICU\n", argv[0]);
      fprintf(stderr, "Options:\n"
              " -h     or  --help                 - Print this help message.\n"
              " -m     or  --millisecond-time     - Print the current UTC time in milliseconds.\n"
              " -d <dir>   or  --icudatadir <dir> - Set the ICU Data Directory\n"
              " -v                                - Print version and configuration information about ICU\n"
              " -L         or  --list-plugins     - List and diagnose issues with ICU Plugins\n"
              " -K         or  --cleanup          - Call u_cleanup() before exitting (will attempt to unload plugins)\n"
              "\n"
              "If no arguments are given, the tool will print ICU version and configuration information.\n"
              );
      fprintf(stderr, "International Components for Unicode %s\n%s\n", U_ICU_VERSION, U_COPYRIGHT_STRING );
      return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
    }
    
    if(options[2].doesOccur) {
      u_setDataDirectory(options[2].value);
    }

    if(options[5].doesOccur) {
      cmd_millis();
      didSomething=TRUE;
    } 
    if(options[4].doesOccur) {
      cmd_listplugins();
      didSomething = TRUE;
    }
    
    if(options[3].doesOccur) {
      cmd_version(FALSE);
      didSomething = TRUE;
    }
        
    if(options[6].doesOccur) {  /* 2nd part of version: cleanup */
      cmd_cleanup();
      didSomething = TRUE;
    }
        
    if(!didSomething) {
      cmd_version(FALSE);  /* at least print the version # */
    }

    return U_FAILURE(errorCode);
}
extern int
main(int argc, char* argv[]) {
    UErrorCode errorCode = U_ZERO_ERROR;
    UBool didSomething = FALSE;
    
    /* preset then read command line options */
    argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options);

    /* error handling, printing usage message */
    if(argc<0) {
        fprintf(stderr,
            "error in command line argument \"%s\"\n",
            argv[-argc]);
    }
    if( options[0].doesOccur || options[1].doesOccur) {
      fprintf(stderr, "%s: Output information about the current ICU\n", argv[0]);
      fprintf(stderr, "Options:\n"
              " -h     or  --help                 - Print this help message.\n"
              " -m     or  --millisecond-time     - Print the current UTC time in milliseconds.\n"
              " -d <dir>   or  --icudatadir <dir> - Set the ICU Data Directory\n"
              " -v                                - Print version and configuration information about ICU\n"
#if UCONFIG_ENABLE_PLUGINS
              " -L         or  --list-plugins     - List and diagnose issues with ICU Plugins\n"
#endif
              " -K         or  --cleanup          - Call u_cleanup() before exitting (will attempt to unload plugins)\n"
              "\n"
              "If no arguments are given, the tool will print ICU version and configuration information.\n"
              );
      fprintf(stderr, "International Components for Unicode %s\n%s\n", U_ICU_VERSION, U_COPYRIGHT_STRING );
      return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
    }
    
    if(options[2].doesOccur) {
      u_setDataDirectory(options[2].value);
    }

    if(options[5].doesOccur) {
      cmd_millis();
      didSomething=TRUE;
    } 
    if(options[4].doesOccur) {
      cmd_listplugins();
      didSomething = TRUE;
    }

    if(options[3].doesOccur) {
      cmd_version(FALSE, errorCode);
      didSomething = TRUE;
    }

    if(options[7].doesOccur) {  /* 2nd part of version: cleanup */
      FILE *out = fopen(options[7].value, "w");
      if(out==NULL) {
        fprintf(stderr,"ERR: can't write to XML file %s\n", options[7].value);
        return 1;
      }
      /* todo: API for writing DTD? */
      fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
      udbg_writeIcuInfo(out);
      fclose(out);
      didSomething = TRUE;
    }

    if(options[6].doesOccur) {  /* 2nd part of version: cleanup */
      cmd_cleanup();
      didSomething = TRUE;
    }

    if(!didSomething) {
      cmd_version(FALSE, errorCode);  /* at least print the version # */
    }

    return U_FAILURE(errorCode);
}