関数 | |
static char * | strerror (int errno) |
static void | prtcon (const char *msg, poptContext con) |
void | poptSetExecPath (poptContext con, const char *path, int allowAbsolute) |
Limit search for executables. | |
static void | invokeCallbacksPRE (poptContext con, const struct poptOption *opt) |
static void | invokeCallbacksPOST (poptContext con, const struct poptOption *opt) |
static void | invokeCallbacksOPTION (poptContext con, const struct poptOption *opt, const struct poptOption *myOpt, const void *myData, int shorty) |
poptContext | poptGetContext (const char *name, int argc, const char **argv, const struct poptOption *options, int flags) |
Initialize popt context. | |
static void | cleanOSE (struct optionStackEntry *os) |
void | poptResetContext (poptContext con) |
Reinitialize popt context. | |
static int | handleExec (poptContext con, const char *longName, char shortName) |
static int | handleAlias (poptContext con, const char *longName, char shortName, const char *nextCharArg) |
static int | execCommand (poptContext con) |
static struct poptOption * | findOption (const struct poptOption *opt, const char *longName, char shortName, poptCallbackType *callback, const void **callbackData, int singleDash) |
static const char * | findNextArg (poptContext con, unsigned argx, int delete_arg) |
static const char * | expandNextArg (poptContext con, const char *s) |
static void | poptStripArg (poptContext con, int which) |
int | poptSaveLong (long *arg, int argInfo, long aLong) |
Save a long, performing logical operation with value. | |
int | poptSaveInt (int *arg, int argInfo, long aLong) |
Save an integer, performing logical operation with value. | |
int | poptGetNextOpt (poptContext con) |
Return value of next option found. | |
const char * | poptGetOptArg (poptContext con) |
Return next option argument (if any). | |
const char * | poptGetArg (poptContext con) |
Return next argument. | |
const char * | poptPeekArg (poptContext con) |
Peek at current argument. | |
const char ** | poptGetArgs (poptContext con) |
Return remaining arguments. | |
poptContext | poptFreeContext (poptContext con) |
Destroy context. | |
int | poptAddAlias (poptContext con, struct poptAlias alias, int flags) |
Add alias to context. | |
int | poptAddItem (poptContext con, poptItem newItem, int flags) |
Add alias/exec item to context. | |
const char * | poptBadOption (poptContext con, int flags) |
Return the option which caused the most recent error. | |
const char * | poptStrerror (const int error) |
Return formatted error string for popt failure. | |
int | poptStuffArgs (poptContext con, const char **argv) |
Add arguments to context. | |
const char * | poptGetInvocationName (poptContext con) |
Return argv[0] from context. | |
int | poptStrippedArgv (poptContext con, int argc, char **argv) |
Shuffle argv pointers to remove stripped args, returns new argc. | |
変数 | |
int | _popt_debug = 0 |
popt.c で定義されています。
static char* strerror | ( | int | errno | ) | [static] |
参照先 sys_errlist.
参照元 _tdb_lockall()・_tdb_unlockall()・ads_errstr()・aixjfs2_get_nfs4_acl()・aixjfs2_get_posix_acl()・aixjfs2_getacl_alloc()・aixjfs2_process_smbacl()・aixjfs2_query_acl_support()・aixjfs2_sys_acl_set_fd()・aixjfs2_sys_acl_set_file()・audit_chmod()・audit_chmod_acl()・audit_close()・audit_fchmod()・audit_fchmod_acl()・audit_mkdir()・audit_open()・audit_opendir()・audit_rename()・audit_rmdir()・audit_unlink()・backup_registry_key()・call_trans2qfilepathinfo()・call_trans2qfsinfo()・call_trans2setfilepathinfo()・cb_itemsignal()・cb_select_child()・cb_wholenet()・change_dir_owner_to_parent()・change_file_owner_to_parent()・check_client_uid()・cifs_resolver()・cli_connect()・cli_errstr()・cli_send_smb()・client_inaddr()・cm_prepare_connection()・cmd_chmod()・cmd_chown()・cmd_close()・cmd_closedir()・cmd_fchmod()・cmd_fchown()・cmd_fstat()・cmd_fsync()・cmd_ftruncate()・cmd_getwd()・cmd_link()・cmd_lock()・cmd_lseek()・cmd_lstat()・cmd_mkdir()・cmd_mknod()・cmd_mput()・cmd_open()・cmd_opendir()・cmd_pathfunc()・cmd_read()・cmd_readlink()・cmd_realpath()・cmd_rename()・cmd_rmdir()・cmd_stat()・cmd_symlink()・cmd_utime()・cmd_write()・copy_file()・count_num_usershares()・create_conn_struct()・create_local_private_krb5_conf_for_domain()・create_msdfs_link()・create_pipe_sock()・create_posix_acl_from_wire()・create_tdb()・cups_connect()・decode_key_description()・delete_memory_creds()・disk_quotas_vxfs()・dns_send_req()・do_cd()・do_daemon_stack_trace()・do_get()・do_global_checks()・do_krb5_kpasswd_request()・do_log()・do_mkdir()・do_put()・dptr_get()・dump_all_namelists()・expect()・fail_readraw()・fcntl_getlock()・fcntl_lock()・fd_open()・fetch_database_to_ldif()・find_new_dc()・fork_child_dc_connect()・fork_domain_child()・fullpath()・get_dir_entry()・get_ea_dos_attribute()・get_lanman2_dir_entry()・get_password_file()・get_password_from_file()・get_peer_addr()・get_server_info()・get_share_list()・get_socket_addr()・get_socket_port()・gpfs_get_nfs4_acl()・gpfs_getacl_alloc()・gpfsacl_get_posix_acl()・gpfsacl_process_smbacl()・handle_aio_read_complete()・handle_aio_write_complete()・hpux_acl_call_present()・hpux_acl_get_file()・hpux_aclsort_call_present()・hpuxacl_sys_acl_get_file()・hpuxacl_sys_acl_set_file()・info_fn()・init_gpfs()・init_mount()・initialise_wins()・initialize_winbindd_cache()・inotify_setup()・inotify_watch()・iprint_cache_reload()・iprint_job_delete()・iprint_job_pause()・iprint_job_resume()・iprint_job_submit()・iprint_queue_get()・irix_init_kernel_oplocks()・irix_oplock_receive_message()・irix_oplocks_available()・irix_release_kernel_oplock()・irix_set_kernel_oplock()・is_msdfs_link()・lang_tdb_init()・ldap_open_with_timeout()・linux_release_kernel_oplock()・linux_set_kernel_oplock()・load_inherited_info()・load_lmhosts_file()・load_usershare_service()・lock_mtab()・main()・make_connection_with_chdir()・make_subnet()・manage_squid_request()・map_file()・map_username()・message_notify()・mkdir_internal()・nb_readx()・nb_writex()・net_time_set()・net_usershare()・net_usershare_add()・net_usershare_delete()・nt_printing_init()・open_file()・open_socket_in()・open_socket_out()・open_sockets_smbd()・open_tdb()・OpenConfFile()・OpenDir()・parse_usershare_file()・pidfile_create()・poptStrerror()・posix_fcntl_getlock()・posix_fcntl_lock()・posixacl_sys_acl_set_file()・preallocate_space()・print_job_start()・print_stack_trace()・process()・process_blocking_lock_queue()・process_file()・process_usershare_file()・profile_setup()・pw_file_lock()・pw_file_unlock()・py_tdb_close()・py_tdb_open()・read_block()・read_data()・read_data_until()・read_socket_with_timeout()・read_target_host()・read_udp_socket()・receive_packet()・recycle_create_dir()・recycle_do_touch()・recycle_get_file_size()・recycle_unlink()・regdb_init()・regdb_open()・regf_hbin_allocate()・regfio_open()・release_posix_lock_windows_flavour()・remove_from_mtab()・remove_posix_acl()・reopen_logs()・reply_checkpath()・reply_getatr()・reply_writebraw()・restore_registry_key()・rmdir_internals()・rpc_share_allowedusers_internals()・schedule_aio_read_and_X()・schedule_aio_write_and_X()・send_cldap_netlogon()・send_file_readbraw()・send_file_readX()・send_message()・send_smb()・send_udp()・set_canon_ace_list()・set_ea_dos_attribute()・set_gpfs_sharemode()・set_maxfiles()・set_nt_acl()・set_posix_lock_posix_flavour()・set_posix_lock_windows_flavour()・set_process_capability()・set_socket_options()・set_unix_posix_acl()・set_unix_posix_default_acl()・setup_out_fd()・share_info_db_init()・smb_acl_to_posix()・smb_acl_to_tru64_acl()・smb_download_dir()・smb_download_file()・smb_nscd_flush_cache()・smb_panic()・smb_permset_to_tru64()・smb_set_file_dosmode()・smb_set_nt_acl_nfs4()・smb_umount()・smbacl4_GetFileOwner()・smbrun_internal()・smbrunsecret()・sock_exec()・solaris_acl_get_fd()・solaris_acl_get_file()・solaris_attropen()・solaris_list_xattr()・solaris_openat()・solarisacl_sys_acl_get_fd()・solarisacl_sys_acl_get_file()・solarisacl_sys_acl_set_fd()・solarisacl_sys_acl_set_file()・start_background_queue()・startlmhosts()・startsmbfilepwent()・store_inheritance_attributes()・store_memory_creds()・sys_disk_free()・sys_fgetxattr()・sys_get_quota()・sys_getxattr()・sys_lgetxattr()・sys_set_quota()・sys_set_vfs_quota()・tdb_alloc_read()・tdb_expand_file()・tdb_mmap()・tdb_nextkey()・tdb_open_ex()・tdb_read()・tdb_reopen()・tdb_write()・tdbsam_new_rid()・test_ftruncate()・test_socketpair()・timeout_processing()・tool_list()・torture_utable()・transaction_sync()・transfer_file_internal()・tru64_ace_to_smb_ace()・tru64_acl_to_smb_acl()・tru64acl_sys_acl_set_file()・umount_check_perm()・umount_ok()・unix_error_packet()・unix_mode()・unmap_file()・user_can_read_file()・vfs_fill_sparse()・vfs_GetWd()・watch_destructor()・wcp_file_size_change()・winbindd_check_cache_size()・winbindd_pam_logoff()・wins_write_database()・write_block()・write_browse_list()・write_data()・write_data_at_offset()・write_socket()・writetarheader().
00027 { 00028 extern int sys_nerr; 00029 extern char * sys_errlist[]; 00030 00031 if ((0 <= errno) && (errno < sys_nerr)) 00032 return sys_errlist[errno]; 00033 else 00034 return POPT_("unknown errno"); 00035 }
static void prtcon | ( | const char * | msg, | |
poptContext | con | |||
) | [static] |
参照先 optionStackEntry::argv・fprintf()・optionStackEntry::next・optionStackEntry::nextArg・optionStackEntry::nextCharArg・poptContext_s::os.
00040 { 00041 if (msg) fprintf(stderr, "%s", msg); 00042 fprintf(stderr, "\tcon %p os %p nextCharArg \"%s\" nextArg \"%s\" argv[%d] \"%s\"\n", 00043 con, con->os, 00044 (con->os->nextCharArg ? con->os->nextCharArg : ""), 00045 (con->os->nextArg ? con->os->nextArg : ""), 00046 con->os->next, 00047 (con->os->argv && con->os->argv[con->os->next] 00048 ? con->os->argv[con->os->next] : "")); 00049 }
void poptSetExecPath | ( | poptContext | con, | |
const char * | path, | |||
int | allowAbsolute | |||
) |
Limit search for executables.
con | context | |
path | single path to search for executables | |
allowAbsolute | absolute paths only? |
参照先 _free()・poptContext_s::execAbsolute・poptContext_s::execPath・xstrdup().
00053 { 00054 con->execPath = (const char *)_free(con->execPath); 00055 con->execPath = xstrdup(path); 00056 con->execAbsolute = allowAbsolute; 00057 /*@-nullstate@*/ /* LCL: con->execPath can be NULL? */ 00058 return; 00059 /*@=nullstate@*/ 00060 }
static void invokeCallbacksPRE | ( | poptContext | con, | |
const struct poptOption * | opt | |||
) | [static] |
参照先 poptOption::arg・poptOption::argInfo・poptOption::descrip・poptOption::longName・POPT_CALLBACK_REASON_PRE・poptOption::shortName.
参照元 poptGetContext().
00065 { 00066 if (opt != NULL) 00067 for (; opt->longName || opt->shortName || opt->arg; opt++) { 00068 if (opt->arg == NULL) continue; /* XXX program error. */ 00069 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { 00070 /* Recurse on included sub-tables. */ 00071 invokeCallbacksPRE(con, (const struct poptOption *)opt->arg); 00072 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK && 00073 (opt->argInfo & POPT_CBFLAG_PRE)) 00074 { /*@-castfcnptr@*/ 00075 poptCallbackType cb = (poptCallbackType)opt->arg; 00076 /*@=castfcnptr@*/ 00077 /* Perform callback. */ 00078 /*@-moduncon -noeffectuncon @*/ 00079 cb(con, POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip); 00080 /*@=moduncon =noeffectuncon @*/ 00081 } 00082 } 00083 }
static void invokeCallbacksPOST | ( | poptContext | con, | |
const struct poptOption * | opt | |||
) | [static] |
参照先 poptOption::arg・poptOption::argInfo・poptOption::descrip・poptOption::longName・POPT_CALLBACK_REASON_POST・poptOption::shortName.
参照元 poptGetNextOpt().
00088 { 00089 if (opt != NULL) 00090 for (; opt->longName || opt->shortName || opt->arg; opt++) { 00091 if (opt->arg == NULL) continue; /* XXX program error. */ 00092 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { 00093 /* Recurse on included sub-tables. */ 00094 invokeCallbacksPOST(con, (const struct poptOption *)opt->arg); 00095 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK && 00096 (opt->argInfo & POPT_CBFLAG_POST)) 00097 { /*@-castfcnptr@*/ 00098 poptCallbackType cb = (poptCallbackType)opt->arg; 00099 /*@=castfcnptr@*/ 00100 /* Perform callback. */ 00101 /*@-moduncon -noeffectuncon @*/ 00102 cb(con, POPT_CALLBACK_REASON_POST, NULL, NULL, opt->descrip); 00103 /*@=moduncon =noeffectuncon @*/ 00104 } 00105 } 00106 }
static void invokeCallbacksOPTION | ( | poptContext | con, | |
const struct poptOption * | opt, | |||
const struct poptOption * | myOpt, | |||
const void * | myData, | |||
int | shorty | |||
) | [static] |
参照先 poptOption::arg・poptOption::argInfo・poptOption::longName・poptOption::shortName.
参照元 poptGetNextOpt().
00114 { 00115 const struct poptOption * cbopt = NULL; 00116 00117 if (opt != NULL) 00118 for (; opt->longName || opt->shortName || opt->arg; opt++) { 00119 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { 00120 /* Recurse on included sub-tables. */ 00121 if (opt->arg != NULL) /* XXX program error */ 00122 invokeCallbacksOPTION(con, (const struct poptOption *)opt->arg, 00123 myOpt, myData, shorty); 00124 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK && 00125 !(opt->argInfo & POPT_CBFLAG_SKIPOPTION)) { 00126 /* Save callback info. */ 00127 cbopt = opt; 00128 } else if (cbopt != NULL && 00129 ((myOpt->shortName && opt->shortName && shorty && 00130 myOpt->shortName == opt->shortName) || 00131 (myOpt->longName && opt->longName && 00132 /*@-nullpass@*/ /* LCL: opt->longName != NULL */ 00133 !strcmp(myOpt->longName, opt->longName))) 00134 /*@=nullpass@*/ 00135 ) 00136 { /*@-castfcnptr@*/ 00137 poptCallbackType cb = (poptCallbackType)cbopt->arg; 00138 /*@=castfcnptr@*/ 00139 const void * cbData = (cbopt->descrip ? cbopt->descrip : myData); 00140 /* Perform callback. */ 00141 if (cb != NULL) { /* XXX program error */ 00142 /*@-moduncon -noeffectuncon @*/ 00143 cb(con, POPT_CALLBACK_REASON_OPTION, myOpt, 00144 con->os->nextArg, cbData); 00145 /*@=moduncon =noeffectuncon @*/ 00146 } 00147 /* Terminate (unless explcitly continuing). */ 00148 if (!(cbopt->argInfo & POPT_CBFLAG_CONTINUE)) 00149 return; 00150 } 00151 } 00152 }
poptContext poptGetContext | ( | const char * | name, | |
int | argc, | |||
const char ** | argv, | |||
const struct poptOption * | options, | |||
int | flags | |||
) |
Initialize popt context.
name | context name (usually argv[0] program name) | |
argc | no. of arguments | |
argv | argument array | |
options | address of popt option table | |
flags | or'd POPT_CONTEXT_* bits |
参照先 invokeCallbacksPRE()・options・t.
参照元 main()・parse_quota_set()・rpc_reg_shutdown_internals().
00156 { 00157 poptContext con = (poptContext)malloc(sizeof(*con)); 00158 00159 if (con == NULL) return NULL; /* XXX can't happen */ 00160 memset(con, 0, sizeof(*con)); 00161 00162 con->os = con->optionStack; 00163 con->os->argc = argc; 00164 /*@-dependenttrans -assignexpose@*/ /* FIX: W2DO? */ 00165 con->os->argv = argv; 00166 /*@=dependenttrans =assignexpose@*/ 00167 con->os->argb = NULL; 00168 00169 if (!(flags & POPT_CONTEXT_KEEP_FIRST)) 00170 con->os->next = 1; /* skip argv[0] */ 00171 00172 con->leftovers = (const char **)calloc( (argc + 1), 00173 sizeof(*con->leftovers) ); 00174 /*@-dependenttrans -assignexpose@*/ /* FIX: W2DO? */ 00175 con->options = options; 00176 /*@=dependenttrans =assignexpose@*/ 00177 con->aliases = NULL; 00178 con->numAliases = 0; 00179 con->flags = flags; 00180 con->execs = NULL; 00181 con->numExecs = 0; 00182 con->finalArgvAlloced = argc * 2; 00183 con->finalArgv = (const char **)calloc( con->finalArgvAlloced, 00184 sizeof(*con->finalArgv) ); 00185 con->execAbsolute = 1; 00186 con->arg_strip = NULL; 00187 00188 if (getenv("POSIXLY_CORRECT") || getenv("POSIX_ME_HARDER")) 00189 con->flags |= POPT_CONTEXT_POSIXMEHARDER; 00190 00191 if (name) { 00192 char * t = (char *)malloc(strlen(name) + 1); 00193 if (t) con->appName = strcpy(t, name); 00194 } 00195 00196 /*@-internalglobs@*/ 00197 invokeCallbacksPRE(con, con->options); 00198 /*@=internalglobs@*/ 00199 00200 return con; 00201 }
static void cleanOSE | ( | struct optionStackEntry * | os | ) | [static] |
参照先 _free()・optionStackEntry::argb・optionStackEntry::argv・optionStackEntry::nextArg.
参照元 poptGetNextOpt()・poptResetContext().
00207 { 00208 os->nextArg = (const char *)_free(os->nextArg); 00209 os->argv = (const char **)_free(os->argv); 00210 os->argb = (pbm_set *)PBM_FREE(os->argb); 00211 }
void poptResetContext | ( | poptContext | con | ) |
Reinitialize popt context.
con | context |
参照先 _free()・poptContext_s::arg_strip・optionStackEntry::argb・cleanOSE()・optionStackEntry::currAlias・poptContext_s::doExec・poptContext_s::finalArgv・poptContext_s::finalArgvCount・optionStackEntry::next・optionStackEntry::nextArg・optionStackEntry::nextCharArg・poptContext_s::nextLeftover・poptContext_s::numLeftovers・poptContext_s::optionStack・poptContext_s::os・poptContext_s::restLeftover.
参照元 poptFreeContext().
00215 { 00216 int i; 00217 00218 if (con == NULL) return; 00219 while (con->os > con->optionStack) { 00220 cleanOSE(con->os--); 00221 } 00222 con->os->argb = (pbm_set *)PBM_FREE(con->os->argb); 00223 con->os->currAlias = NULL; 00224 con->os->nextCharArg = NULL; 00225 con->os->nextArg = NULL; 00226 con->os->next = 1; /* skip argv[0] */ 00227 00228 con->numLeftovers = 0; 00229 con->nextLeftover = 0; 00230 con->restLeftover = 0; 00231 con->doExec = NULL; 00232 00233 if (con->finalArgv != NULL) 00234 for (i = 0; i < con->finalArgvCount; i++) { 00235 /*@-unqualifiedtrans@*/ /* FIX: typedef double indirection. */ 00236 con->finalArgv[i] = (const char *)_free(con->finalArgv[i]); 00237 /*@=unqualifiedtrans@*/ 00238 } 00239 00240 con->finalArgvCount = 0; 00241 con->arg_strip = ( pbm_set *)PBM_FREE(con->arg_strip); 00242 /*@-nullstate@*/ /* FIX: con->finalArgv != NULL */ 00243 return; 00244 /*@=nullstate@*/ 00245 }
static int handleExec | ( | poptContext | con, | |
const char * | longName, | |||
char | shortName | |||
) | [static] |
参照先 poptContext_s::doExec・poptContext_s::execs・poptContext_s::finalArgv・poptContext_s::finalArgvAlloced・poptContext_s::finalArgvCount・poptContext_s::flags・poptOption::longName・poptContext_s::numExecs・poptItem_s::option・poptOption::shortName・sprintf().
参照元 poptGetNextOpt().
00255 { 00256 poptItem item; 00257 int i; 00258 00259 if (con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */ 00260 return 0; 00261 00262 for (i = con->numExecs - 1; i >= 0; i--) { 00263 item = con->execs + i; 00264 if (longName && !(item->option.longName && 00265 !strcmp(longName, item->option.longName))) 00266 continue; 00267 else if (shortName != item->option.shortName) 00268 continue; 00269 break; 00270 } 00271 if (i < 0) return 0; 00272 00273 00274 if (con->flags & POPT_CONTEXT_NO_EXEC) 00275 return 1; 00276 00277 if (con->doExec == NULL) { 00278 con->doExec = con->execs + i; 00279 return 1; 00280 } 00281 00282 /* We already have an exec to do; remember this option for next 00283 time 'round */ 00284 if ((con->finalArgvCount + 1) >= (con->finalArgvAlloced)) { 00285 con->finalArgvAlloced += 10; 00286 con->finalArgv = (const char **)realloc(con->finalArgv, 00287 sizeof(*con->finalArgv) * con->finalArgvAlloced); 00288 } 00289 00290 i = con->finalArgvCount++; 00291 if (con->finalArgv != NULL) /* XXX can't happen */ 00292 { char *s = (char *)malloc((longName ? strlen(longName) : 0) + 3); 00293 if (s != NULL) { /* XXX can't happen */ 00294 if (longName) 00295 sprintf(s, "--%s", longName); 00296 else 00297 sprintf(s, "-%c", shortName); 00298 con->finalArgv[i] = s; 00299 } else 00300 con->finalArgv[i] = NULL; 00301 } 00302 00303 /*@-nullstate@*/ /* FIX: con->finalArgv[] == NULL */ 00304 return 1; 00305 /*@=nullstate@*/ 00306 }
static int handleAlias | ( | poptContext | con, | |
const char * | longName, | |||
char | shortName, | |||
const char * | nextCharArg | |||
) | [static] |
参照先 poptContext_s::aliases・optionStackEntry::argb・optionStackEntry::argc・poptItem_s::argc・optionStackEntry::argv・poptItem_s::argv・optionStackEntry::currAlias・poptOption::longName・optionStackEntry::next・optionStackEntry::nextArg・optionStackEntry::nextCharArg・poptContext_s::numAliases・poptItem_s::option・poptContext_s::optionStack・poptContext_s::os・poptDupArgv()・poptOption::shortName・optionStackEntry::stuffed.
参照元 poptGetNextOpt().
00316 { 00317 poptItem item = con->os->currAlias; 00318 int rc; 00319 int i; 00320 00321 if (item) { 00322 if (longName && (item->option.longName && 00323 !strcmp(longName, item->option.longName))) 00324 return 0; 00325 if (shortName && shortName == item->option.shortName) 00326 return 0; 00327 } 00328 00329 if (con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */ 00330 return 0; 00331 00332 for (i = con->numAliases - 1; i >= 0; i--) { 00333 item = con->aliases + i; 00334 if (longName && !(item->option.longName && 00335 !strcmp(longName, item->option.longName))) 00336 continue; 00337 else if (shortName != item->option.shortName) 00338 continue; 00339 break; 00340 } 00341 if (i < 0) return 0; 00342 00343 if ((con->os - con->optionStack + 1) == POPT_OPTION_DEPTH) 00344 return POPT_ERROR_OPTSTOODEEP; 00345 00346 /*@-boundsread@*/ 00347 if (nextCharArg && *nextCharArg) 00348 con->os->nextCharArg = nextCharArg; 00349 /*@=boundsread@*/ 00350 00351 con->os++; 00352 con->os->next = 0; 00353 con->os->stuffed = 0; 00354 con->os->nextArg = NULL; 00355 con->os->nextCharArg = NULL; 00356 con->os->currAlias = con->aliases + i; 00357 rc = poptDupArgv(con->os->currAlias->argc, con->os->currAlias->argv, 00358 &con->os->argc, &con->os->argv); 00359 con->os->argb = NULL; 00360 00361 return (rc ? rc : 1); 00362 }
static int execCommand | ( | poptContext | con | ) | [static] |
参照先 _popt_debug・alloca()・poptItem_s::argc・poptItem_s::argv・poptContext_s::doExec・poptContext_s::execAbsolute・poptContext_s::execPath・poptContext_s::finalArgv・poptContext_s::finalArgvCount・findProgramPath()・fprintf()・poptContext_s::leftovers・poptContext_s::numLeftovers・sprintf().
参照元 poptGetNextOpt().
00368 { 00369 poptItem item = con->doExec; 00370 const char ** argv; 00371 int argc = 0; 00372 int rc; 00373 00374 if (item == NULL) /*XXX can't happen*/ 00375 return POPT_ERROR_NOARG; 00376 00377 if (item->argv == NULL || item->argc < 1 || 00378 (!con->execAbsolute && strchr(item->argv[0], '/'))) 00379 return POPT_ERROR_NOARG; 00380 00381 argv = (const char **)malloc( 00382 sizeof(*argv) * (6 + item->argc + con->numLeftovers + con->finalArgvCount)); 00383 if (argv == NULL) return POPT_ERROR_MALLOC; /* XXX can't happen */ 00384 00385 if (!strchr(item->argv[0], '/') && con->execPath) { 00386 char *s = (char *)alloca( 00387 strlen(con->execPath) + strlen(item->argv[0]) + sizeof("/")); 00388 sprintf(s, "%s/%s", con->execPath, item->argv[0]); 00389 argv[argc] = s; 00390 } else { 00391 argv[argc] = findProgramPath(item->argv[0]); 00392 } 00393 if (argv[argc++] == NULL) return POPT_ERROR_NOARG; 00394 00395 if (item->argc > 1) { 00396 memcpy(argv + argc, item->argv + 1, sizeof(*argv) * (item->argc - 1)); 00397 argc += (item->argc - 1); 00398 } 00399 00400 if (con->finalArgv != NULL && con->finalArgvCount > 0) { 00401 memcpy(argv + argc, con->finalArgv, 00402 sizeof(*argv) * con->finalArgvCount); 00403 argc += con->finalArgvCount; 00404 } 00405 00406 if (con->leftovers != NULL && con->numLeftovers > 0) { 00407 #if 0 00408 argv[argc++] = "--"; 00409 #endif 00410 memcpy(argv + argc, con->leftovers, sizeof(*argv) * con->numLeftovers); 00411 argc += con->numLeftovers; 00412 } 00413 00414 argv[argc] = NULL; 00415 00416 #ifdef __hpux 00417 rc = setresuid(getuid(), getuid(),-1); 00418 if (rc) return POPT_ERROR_ERRNO; 00419 #else 00420 /* 00421 * XXX " ... on BSD systems setuid() should be preferred over setreuid()" 00422 * XXX sez' Timur Bakeyev <mc@bat.ru> 00423 * XXX from Norbert Warmuth <nwarmuth@privat.circular.de> 00424 */ 00425 #if defined(HAVE_SETUID) 00426 rc = setuid(getuid()); 00427 if (rc) return POPT_ERROR_ERRNO; 00428 #elif defined (HAVE_SETREUID) 00429 rc = setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */ 00430 if (rc) return POPT_ERROR_ERRNO; 00431 #else 00432 ; /* Can't drop privileges */ 00433 #endif 00434 #endif 00435 00436 if (argv[0] == NULL) 00437 return POPT_ERROR_NOARG; 00438 00439 #ifdef MYDEBUG 00440 if (_popt_debug) 00441 { const char ** avp; 00442 fprintf(stderr, "==> execvp(%s) argv[%d]:", argv[0], argc); 00443 for (avp = argv; *avp; avp++) 00444 fprintf(stderr, " '%s'", *avp); 00445 fprintf(stderr, "\n"); 00446 } 00447 #endif 00448 00449 rc = execvp(argv[0], (char *const *)argv); 00450 /* notreached */ 00451 if (rc) { 00452 return POPT_ERROR_ERRNO; 00453 } 00454 00455 return 0; 00456 }
static struct poptOption* findOption | ( | const struct poptOption * | opt, | |
const char * | longName, | |||
char | shortName, | |||
poptCallbackType * | callback, | |||
const void ** | callbackData, | |||
int | singleDash | |||
) | [static] |
参照先 poptOption::arg・poptOption::argInfo・poptOption::descrip・poptOption::longName・poptOption::shortName.
参照元 poptGetNextOpt().
00467 { 00468 const struct poptOption * cb = NULL; 00469 00470 /* This happens when a single - is given */ 00471 if (singleDash && !shortName && (longName && *longName == '\0')) 00472 shortName = '-'; 00473 00474 for (; opt->longName || opt->shortName || opt->arg; opt++) { 00475 00476 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { 00477 const struct poptOption * opt2; 00478 00479 /* Recurse on included sub-tables. */ 00480 if (opt->arg == NULL) continue; /* XXX program error */ 00481 opt2 = findOption((const struct poptOption *)opt->arg, longName, 00482 shortName, callback, 00483 callbackData, singleDash); 00484 if (opt2 == NULL) continue; 00485 /* Sub-table data will be inheirited if no data yet. */ 00486 if (!(callback && *callback)) return opt2; 00487 if (!(callbackData && *callbackData == NULL)) return opt2; 00488 /*@-observertrans -dependenttrans @*/ 00489 *callbackData = opt->descrip; 00490 /*@=observertrans =dependenttrans @*/ 00491 return opt2; 00492 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) { 00493 cb = opt; 00494 } else if (longName && opt->longName && 00495 (!singleDash || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) && 00496 /*@-nullpass@*/ /* LCL: opt->longName != NULL */ 00497 !strcmp(longName, opt->longName)) 00498 /*@=nullpass@*/ 00499 { 00500 break; 00501 } else if (shortName && shortName == opt->shortName) { 00502 break; 00503 } 00504 } 00505 00506 if (!opt->longName && !opt->shortName) 00507 return NULL; 00508 /*@-modobserver -mods @*/ 00509 if (callback) *callback = NULL; 00510 if (callbackData) *callbackData = NULL; 00511 if (cb) { 00512 if (callback) 00513 /*@-castfcnptr@*/ 00514 *callback = (poptCallbackType)cb->arg; 00515 /*@=castfcnptr@*/ 00516 if (!(cb->argInfo & POPT_CBFLAG_INC_DATA)) { 00517 if (callbackData) 00518 /*@-observertrans@*/ /* FIX: typedef double indirection. */ 00519 *callbackData = cb->descrip; 00520 /*@=observertrans@*/ 00521 } 00522 } 00523 /*@=modobserver =mods @*/ 00524 00525 return opt; 00526 }
static const char* findNextArg | ( | poptContext | con, | |
unsigned | argx, | |||
int | delete_arg | |||
) | [static] |
参照先 optionStackEntry::argb・optionStackEntry::argc・optionStackEntry::argv・optionStackEntry::next・poptContext_s::optionStack・poptContext_s::os.
参照元 expandNextArg().
00534 { 00535 struct optionStackEntry * os = con->os; 00536 const char * arg; 00537 00538 do { 00539 int i; 00540 arg = NULL; 00541 while (os->next == os->argc && os > con->optionStack) os--; 00542 if (os->next == os->argc && os == con->optionStack) break; 00543 if (os->argv != NULL) 00544 for (i = os->next; i < os->argc; i++) { 00545 /*@-sizeoftype@*/ 00546 if (os->argb && PBM_ISSET(i, os->argb)) 00547 /*@innercontinue@*/ continue; 00548 if (*os->argv[i] == '-') 00549 /*@innercontinue@*/ continue; 00550 if (--argx > 0) 00551 /*@innercontinue@*/ continue; 00552 arg = os->argv[i]; 00553 if (delete_arg) { 00554 if (os->argb == NULL) os->argb = (pbm_set *)PBM_ALLOC(os->argc); 00555 if (os->argb != NULL) /* XXX can't happen */ 00556 PBM_SET(i, os->argb); 00557 } 00558 /*@innerbreak@*/ break; 00559 /*@=sizeoftype@*/ 00560 } 00561 if (os > con->optionStack) os--; 00562 } while (arg == NULL); 00563 return arg; 00564 }
static const char* expandNextArg | ( | poptContext | con, | |
const char * | s | |||
) | [static] |
参照先 c・findNextArg()・t.
参照元 poptGetNextOpt().
00572 { 00573 const char * a = NULL; 00574 size_t alen; 00575 char *t, *te; 00576 size_t tn = strlen(s) + 1; 00577 char c; 00578 00579 te = t = (char *)malloc(tn);; 00580 if (t == NULL) return NULL; /* XXX can't happen */ 00581 while ((c = *s++) != '\0') { 00582 switch (c) { 00583 #if 0 /* XXX can't do this */ 00584 case '\\': /* escape */ 00585 c = *s++; 00586 /*@switchbreak@*/ break; 00587 #endif 00588 case '!': 00589 if (!(s[0] == '#' && s[1] == ':' && s[2] == '+')) 00590 /*@switchbreak@*/ break; 00591 /* XXX Make sure that findNextArg deletes only next arg. */ 00592 if (a == NULL) { 00593 if ((a = findNextArg(con, 1, 1)) == NULL) 00594 /*@switchbreak@*/ break; 00595 } 00596 s += 3; 00597 00598 alen = strlen(a); 00599 tn += alen; 00600 *te = '\0'; 00601 t = (char *)realloc(t, tn); 00602 te = t + strlen(t); 00603 strncpy(te, a, alen); te += alen; 00604 continue; 00605 /*@notreached@*/ /*@switchbreak@*/ break; 00606 default: 00607 /*@switchbreak@*/ break; 00608 } 00609 *te++ = c; 00610 } 00611 *te = '\0'; 00612 t = (char *)realloc(t, strlen(t) + 1); /* XXX memory leak, hard to plug */ 00613 return t; 00614 }
static void poptStripArg | ( | poptContext | con, | |
int | which | |||
) | [static] |
参照先 poptContext_s::arg_strip・optionStackEntry::argc・poptContext_s::optionStack.
参照元 poptGetNextOpt().
00621 { 00622 /*@-sizeoftype@*/ 00623 if (con->arg_strip == NULL) 00624 con->arg_strip = (pbm_set *)PBM_ALLOC(con->optionStack[0].argc); 00625 if (con->arg_strip != NULL) /* XXX can't happen */ 00626 PBM_SET(which, con->arg_strip); 00627 /*@=sizeoftype@*/ 00628 /*@-compdef@*/ /* LCL: con->arg_strip udefined? */ 00629 return; 00630 /*@=compdef@*/ 00631 }
int poptSaveLong | ( | long * | arg, | |
int | argInfo, | |||
long | aLong | |||
) |
Save a long, performing logical operation with value.
arg | integer pointer, aligned on int boundary. | |
argInfo | logical operation (see POPT_ARGFLAG_*) | |
aLong | value to use |
参照元 poptGetNextOpt().
00634 { 00635 /* XXX Check alignment, may fail on funky platforms. */ 00636 if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1))) 00637 return POPT_ERROR_NULLARG; 00638 00639 if (argInfo & POPT_ARGFLAG_NOT) 00640 aLong = ~aLong; 00641 switch (argInfo & POPT_ARGFLAG_LOGICALOPS) { 00642 case 0: 00643 *arg = aLong; 00644 break; 00645 case POPT_ARGFLAG_OR: 00646 *arg |= aLong; 00647 break; 00648 case POPT_ARGFLAG_AND: 00649 *arg &= aLong; 00650 break; 00651 case POPT_ARGFLAG_XOR: 00652 *arg ^= aLong; 00653 break; 00654 default: 00655 return POPT_ERROR_BADOPERATION; 00656 /*@notreached@*/ break; 00657 } 00658 return 0; 00659 }
int poptSaveInt | ( | int * | arg, | |
int | argInfo, | |||
long | aLong | |||
) |
Save an integer, performing logical operation with value.
arg | integer pointer, aligned on int boundary. | |
argInfo | logical operation (see POPT_ARGFLAG_*) | |
aLong | value to use |
参照元 poptGetNextOpt().
00662 { 00663 /* XXX Check alignment, may fail on funky platforms. */ 00664 if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1))) 00665 return POPT_ERROR_NULLARG; 00666 00667 if (argInfo & POPT_ARGFLAG_NOT) 00668 aLong = ~aLong; 00669 switch (argInfo & POPT_ARGFLAG_LOGICALOPS) { 00670 case 0: 00671 *arg = aLong; 00672 break; 00673 case POPT_ARGFLAG_OR: 00674 *arg |= aLong; 00675 break; 00676 case POPT_ARGFLAG_AND: 00677 *arg &= aLong; 00678 break; 00679 case POPT_ARGFLAG_XOR: 00680 *arg ^= aLong; 00681 break; 00682 default: 00683 return POPT_ERROR_BADOPERATION; 00684 /*@notreached@*/ break; 00685 } 00686 return 0; 00687 }
int poptGetNextOpt | ( | poptContext | con | ) |
Return value of next option found.
con | context |
参照先 _free()・alloca()・poptOption::arg・optionStackEntry::argb・optionStackEntry::argc・poptOption::argInfo・optionStackEntry::argv・cleanOSE()・poptContext_s::doExec・errno・execCommand()・expandNextArg()・poptContext_s::finalArgv・poptContext_s::finalArgvAlloced・poptContext_s::finalArgvCount・findOption()・poptContext_s::flags・fprintf()・handleAlias()・handleExec()・invokeCallbacksOPTION()・invokeCallbacksPOST()・poptContext_s::leftovers・poptOption::longName・optionStackEntry::next・optionStackEntry::nextArg・optionStackEntry::nextCharArg・poptContext_s::numLeftovers・poptContext_s::options・poptContext_s::optionStack・poptContext_s::os・poptSaveInt()・poptSaveLong()・poptStripArg()・poptContext_s::restLeftover・poptOption::shortName・sprintf()・poptOption::val・xstrdup().
参照元 main()・parse_quota_set()・rpc_reg_shutdown_internals().
00692 { 00693 const struct poptOption * opt = NULL; 00694 int done = 0; 00695 00696 if (con == NULL) 00697 return -1; 00698 while (!done) { 00699 const char * origOptString = NULL; 00700 poptCallbackType cb = NULL; 00701 const void * cbData = NULL; 00702 const char * longArg = NULL; 00703 int canstrip = 0; 00704 int shorty = 0; 00705 00706 while (!con->os->nextCharArg && con->os->next == con->os->argc 00707 && con->os > con->optionStack) { 00708 cleanOSE(con->os--); 00709 } 00710 if (!con->os->nextCharArg && con->os->next == con->os->argc) { 00711 /*@-internalglobs@*/ 00712 invokeCallbacksPOST(con, con->options); 00713 /*@=internalglobs@*/ 00714 if (con->doExec) return execCommand(con); 00715 return -1; 00716 } 00717 00718 /* Process next long option */ 00719 if (!con->os->nextCharArg) { 00720 char * localOptString, * optString; 00721 int thisopt; 00722 00723 /*@-sizeoftype@*/ 00724 if (con->os->argb && PBM_ISSET(con->os->next, con->os->argb)) { 00725 con->os->next++; 00726 continue; 00727 } 00728 /*@=sizeoftype@*/ 00729 thisopt = con->os->next; 00730 if (con->os->argv != NULL) /* XXX can't happen */ 00731 origOptString = con->os->argv[con->os->next++]; 00732 00733 if (origOptString == NULL) /* XXX can't happen */ 00734 return POPT_ERROR_BADOPT; 00735 00736 if (con->restLeftover || *origOptString != '-') { 00737 if (con->flags & POPT_CONTEXT_POSIXMEHARDER) 00738 con->restLeftover = 1; 00739 if (con->flags & POPT_CONTEXT_ARG_OPTS) { 00740 con->os->nextArg = xstrdup(origOptString); 00741 return 0; 00742 } 00743 if (con->leftovers != NULL) /* XXX can't happen */ 00744 con->leftovers[con->numLeftovers++] = origOptString; 00745 continue; 00746 } 00747 00748 /* Make a copy we can hack at */ 00749 localOptString = optString = 00750 strcpy((char *)alloca(strlen(origOptString) + 1), 00751 origOptString); 00752 00753 if (optString[0] == '\0') 00754 return POPT_ERROR_BADOPT; 00755 00756 if (optString[1] == '-' && !optString[2]) { 00757 con->restLeftover = 1; 00758 continue; 00759 } else { 00760 char *oe; 00761 int singleDash; 00762 00763 optString++; 00764 if (*optString == '-') 00765 singleDash = 0, optString++; 00766 else 00767 singleDash = 1; 00768 00769 /* XXX aliases with arg substitution need "--alias=arg" */ 00770 if (handleAlias(con, optString, '\0', NULL)) 00771 continue; 00772 00773 if (handleExec(con, optString, '\0')) 00774 continue; 00775 00776 /* Check for "--long=arg" option. */ 00777 for (oe = optString; *oe && *oe != '='; oe++) 00778 {}; 00779 if (*oe == '=') { 00780 *oe++ = '\0'; 00781 /* XXX longArg is mapped back to persistent storage. */ 00782 longArg = origOptString + (oe - localOptString); 00783 } 00784 00785 opt = findOption(con->options, optString, '\0', &cb, &cbData, 00786 singleDash); 00787 if (!opt && !singleDash) 00788 return POPT_ERROR_BADOPT; 00789 } 00790 00791 if (!opt) { 00792 con->os->nextCharArg = origOptString + 1; 00793 } else { 00794 if (con->os == con->optionStack && 00795 opt->argInfo & POPT_ARGFLAG_STRIP) 00796 { 00797 canstrip = 1; 00798 poptStripArg(con, thisopt); 00799 } 00800 shorty = 0; 00801 } 00802 } 00803 00804 /* Process next short option */ 00805 /*@-branchstate@*/ /* FIX: W2DO? */ 00806 if (con->os->nextCharArg) { 00807 origOptString = con->os->nextCharArg; 00808 00809 con->os->nextCharArg = NULL; 00810 00811 if (handleAlias(con, NULL, *origOptString, origOptString + 1)) 00812 continue; 00813 00814 if (handleExec(con, NULL, *origOptString)) { 00815 /* Restore rest of short options for further processing */ 00816 origOptString++; 00817 if (*origOptString != '\0') 00818 con->os->nextCharArg = origOptString; 00819 continue; 00820 } 00821 00822 opt = findOption(con->options, NULL, *origOptString, &cb, 00823 &cbData, 0); 00824 if (!opt) 00825 return POPT_ERROR_BADOPT; 00826 shorty = 1; 00827 00828 origOptString++; 00829 if (*origOptString != '\0') 00830 con->os->nextCharArg = origOptString; 00831 } 00832 /*@=branchstate@*/ 00833 00834 if (opt == NULL) return POPT_ERROR_BADOPT; /* XXX can't happen */ 00835 if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) { 00836 if (poptSaveInt((int *)opt->arg, opt->argInfo, 1L)) 00837 return POPT_ERROR_BADOPERATION; 00838 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) { 00839 if (opt->arg) { 00840 if (poptSaveInt((int *)opt->arg, opt->argInfo, (long)opt->val)) 00841 return POPT_ERROR_BADOPERATION; 00842 } 00843 } else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { 00844 con->os->nextArg = (const char *)_free(con->os->nextArg); 00845 /*@-usedef@*/ /* FIX: W2DO? */ 00846 if (longArg) { 00847 /*@=usedef@*/ 00848 longArg = expandNextArg(con, longArg); 00849 con->os->nextArg = longArg; 00850 } else if (con->os->nextCharArg) { 00851 longArg = expandNextArg(con, con->os->nextCharArg); 00852 con->os->nextArg = longArg; 00853 con->os->nextCharArg = NULL; 00854 } else { 00855 while (con->os->next == con->os->argc && 00856 con->os > con->optionStack) { 00857 cleanOSE(con->os--); 00858 } 00859 if (con->os->next == con->os->argc) { 00860 if (!(opt->argInfo & POPT_ARGFLAG_OPTIONAL)) 00861 /*@-compdef@*/ /* FIX: con->os->argv not defined */ 00862 return POPT_ERROR_NOARG; 00863 /*@=compdef@*/ 00864 con->os->nextArg = NULL; 00865 } else { 00866 00867 /* 00868 * Make sure this isn't part of a short arg or the 00869 * result of an alias expansion. 00870 */ 00871 if (con->os == con->optionStack && 00872 (opt->argInfo & POPT_ARGFLAG_STRIP) && 00873 canstrip) { 00874 poptStripArg(con, con->os->next); 00875 } 00876 00877 if (con->os->argv != NULL) { /* XXX can't happen */ 00878 /* XXX watchout: subtle side-effects live here. */ 00879 longArg = con->os->argv[con->os->next++]; 00880 longArg = expandNextArg(con, longArg); 00881 con->os->nextArg = longArg; 00882 } 00883 } 00884 } 00885 longArg = NULL; 00886 00887 if (opt->arg) { 00888 switch (opt->argInfo & POPT_ARG_MASK) { 00889 case POPT_ARG_STRING: 00890 /* XXX memory leak, hard to plug */ 00891 *((const char **) opt->arg) = (con->os->nextArg) 00892 ? xstrdup(con->os->nextArg) : NULL; 00893 /*@switchbreak@*/ break; 00894 00895 case POPT_ARG_INT: 00896 case POPT_ARG_LONG: 00897 { long aLong = 0; 00898 char *end; 00899 00900 if (con->os->nextArg) { 00901 aLong = strtol(con->os->nextArg, &end, 0); 00902 if (!(end && *end == '\0')) 00903 return POPT_ERROR_BADNUMBER; 00904 } 00905 00906 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) { 00907 if (aLong == LONG_MIN || aLong == LONG_MAX) 00908 return POPT_ERROR_OVERFLOW; 00909 if (poptSaveLong((long *)opt->arg, opt->argInfo, aLong)) 00910 return POPT_ERROR_BADOPERATION; 00911 } else { 00912 if (aLong > INT_MAX || aLong < INT_MIN) 00913 return POPT_ERROR_OVERFLOW; 00914 if (poptSaveInt((int *)opt->arg, opt->argInfo, aLong)) 00915 return POPT_ERROR_BADOPERATION; 00916 } 00917 } /*@switchbreak@*/ break; 00918 00919 case POPT_ARG_FLOAT: 00920 case POPT_ARG_DOUBLE: 00921 { double aDouble = 0.0; 00922 char *end; 00923 00924 if (con->os->nextArg) { 00925 /*@-mods@*/ 00926 int saveerrno = errno; 00927 errno = 0; 00928 aDouble = strtod(con->os->nextArg, &end); 00929 if (errno == ERANGE) 00930 return POPT_ERROR_OVERFLOW; 00931 errno = saveerrno; 00932 /*@=mods@*/ 00933 if (*end != '\0') 00934 return POPT_ERROR_BADNUMBER; 00935 } 00936 00937 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_DOUBLE) { 00938 *((double *) opt->arg) = aDouble; 00939 } else { 00940 #ifndef _ABS 00941 #define _ABS(a) ((((a) - 0.0) < DBL_EPSILON) ? -(a) : (a)) 00942 #endif 00943 if ((_ABS(aDouble) - FLT_MAX) > DBL_EPSILON) 00944 return POPT_ERROR_OVERFLOW; 00945 if ((FLT_MIN - _ABS(aDouble)) > DBL_EPSILON) 00946 return POPT_ERROR_OVERFLOW; 00947 *((float *) opt->arg) = aDouble; 00948 } 00949 } /*@switchbreak@*/ break; 00950 default: 00951 fprintf(stdout, 00952 POPT_("option type (%d) not implemented in popt\n"), 00953 (opt->argInfo & POPT_ARG_MASK)); 00954 exit(EXIT_FAILURE); 00955 /*@notreached@*/ /*@switchbreak@*/ break; 00956 } 00957 } 00958 } 00959 00960 if (cb) { 00961 /*@-internalglobs@*/ 00962 invokeCallbacksOPTION(con, con->options, opt, cbData, shorty); 00963 /*@=internalglobs@*/ 00964 } else if (opt->val && ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL)) 00965 done = 1; 00966 00967 if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) { 00968 con->finalArgvAlloced += 10; 00969 con->finalArgv = (const char **)realloc(con->finalArgv, 00970 sizeof(*con->finalArgv) * con->finalArgvAlloced); 00971 } 00972 00973 if (con->finalArgv != NULL) 00974 { char *s = (char *)malloc( 00975 (opt->longName ? strlen(opt->longName) : 0) + 3); 00976 if (s != NULL) { /* XXX can't happen */ 00977 if (opt->longName) 00978 sprintf(s, "%s%s", 00979 ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"), 00980 opt->longName); 00981 else 00982 sprintf(s, "-%c", opt->shortName); 00983 con->finalArgv[con->finalArgvCount++] = s; 00984 } else 00985 con->finalArgv[con->finalArgvCount++] = NULL; 00986 } 00987 00988 if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) 00989 /*@-ifempty@*/ ; /*@=ifempty@*/ 00990 else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) 00991 /*@-ifempty@*/ ; /*@=ifempty@*/ 00992 else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { 00993 if (con->finalArgv != NULL && con->os->nextArg) 00994 con->finalArgv[con->finalArgvCount++] = 00995 /*@-nullpass@*/ /* LCL: con->os->nextArg != NULL */ 00996 xstrdup(con->os->nextArg); 00997 /*@=nullpass@*/ 00998 } 00999 } 01000 01001 return (opt ? opt->val : -1); /* XXX can't happen */ 01002 }
const char* poptGetOptArg | ( | poptContext | con | ) |
Return next option argument (if any).
con | context |
参照先 optionStackEntry::nextArg・poptContext_s::os.
参照元 main()・parse_quota_set().
01006 { 01007 const char * ret = NULL; 01008 /*@-branchstate@*/ 01009 if (con) { 01010 ret = con->os->nextArg; 01011 con->os->nextArg = NULL; 01012 } 01013 /*@=branchstate@*/ 01014 return ret; 01015 }
const char* poptGetArg | ( | poptContext | con | ) |
Return next argument.
con | context |
参照先 poptContext_s::leftovers・poptContext_s::nextLeftover・poptContext_s::numLeftovers.
参照元 main()・parse_quota_set().
01018 { 01019 const char * ret = NULL; 01020 if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers) 01021 ret = con->leftovers[con->nextLeftover++]; 01022 return ret; 01023 }
const char* poptPeekArg | ( | poptContext | con | ) |
Peek at current argument.
con | context |
参照先 poptContext_s::leftovers・poptContext_s::nextLeftover・poptContext_s::numLeftovers.
参照元 main()・parse_quota_set().
01026 { 01027 const char * ret = NULL; 01028 if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers) 01029 ret = con->leftovers[con->nextLeftover]; 01030 return ret; 01031 }
const char** poptGetArgs | ( | poptContext | con | ) |
Return remaining arguments.
con | context |
参照先 poptContext_s::leftovers・poptContext_s::nextLeftover・poptContext_s::numLeftovers.
参照元 main().
01035 { 01036 if (con == NULL || 01037 con->leftovers == NULL || con->numLeftovers == con->nextLeftover) 01038 return NULL; 01039 01040 /* some apps like [like RPM ;-) ] need this NULL terminated */ 01041 con->leftovers[con->numLeftovers] = NULL; 01042 01043 /*@-nullret -nullstate @*/ /* FIX: typedef double indirection. */ 01044 return (con->leftovers + con->nextLeftover); 01045 /*@=nullret =nullstate @*/ 01046 }
poptContext poptFreeContext | ( | poptContext | con | ) |
Destroy context.
con | context |
参照先 _free()・poptContext_s::aliases・poptContext_s::appName・poptContext_s::arg_strip・optionStackEntry::argb・poptOption::argDescrip・poptItem_s::argv・poptOption::descrip・poptContext_s::execPath・poptContext_s::execs・poptContext_s::finalArgv・poptContext_s::leftovers・poptOption::longName・poptContext_s::numAliases・poptContext_s::numExecs・poptItem_s::option・poptContext_s::os・poptContext_s::otherHelp・poptResetContext().
参照元 main().
01050 { 01051 poptItem item; 01052 int i; 01053 01054 if (con == NULL) return con; 01055 poptResetContext(con); 01056 con->os->argb = (pbm_set *)_free(con->os->argb); 01057 01058 if (con->aliases != NULL) 01059 for (i = 0; i < con->numAliases; i++) { 01060 item = con->aliases + i; 01061 /*@-modobserver -observertrans -dependenttrans@*/ 01062 item->option.longName = (const char *)_free(item->option.longName); 01063 item->option.descrip = (const char *)_free(item->option.descrip); 01064 item->option.argDescrip = (const char *)_free(item->option.argDescrip); 01065 /*@=modobserver =observertrans =dependenttrans@*/ 01066 item->argv = (const char **)_free(item->argv); 01067 } 01068 con->aliases = (poptItem)_free(con->aliases); 01069 01070 if (con->execs != NULL) 01071 for (i = 0; i < con->numExecs; i++) { 01072 item = con->execs + i; 01073 /*@-modobserver -observertrans -dependenttrans@*/ 01074 item->option.longName = (const char *)_free(item->option.longName); 01075 item->option.descrip = (const char *)_free(item->option.descrip); 01076 item->option.argDescrip = (const char *)_free(item->option.argDescrip); 01077 /*@=modobserver =observertrans =dependenttrans@*/ 01078 item->argv = (const char **)_free(item->argv); 01079 } 01080 con->execs = (poptItem)_free(con->execs); 01081 01082 con->leftovers = (const char **)_free(con->leftovers); 01083 con->finalArgv = (const char **)_free(con->finalArgv); 01084 con->appName = (const char *)_free(con->appName); 01085 con->otherHelp = (const char *)_free(con->otherHelp); 01086 con->execPath = (const char *)_free(con->execPath); 01087 con->arg_strip = (pbm_set *)PBM_FREE(con->arg_strip); 01088 01089 con = (poptContext)_free(con); 01090 return con; 01091 }
int poptAddAlias | ( | poptContext | con, | |
struct poptAlias | alias, | |||
int | flags | |||
) |
Add alias to context.
con | context | |
alias | alias to add | |
flags | (unused) |
参照先 alloca()・poptAlias::argc・poptAlias::argv・poptAlias::longName・poptAddItem()・poptAlias::shortName.
01095 { 01096 poptItem item = (poptItem)alloca(sizeof(*item)); 01097 memset(item, 0, sizeof(*item)); 01098 item->option.longName = alias.longName; 01099 item->option.shortName = alias.shortName; 01100 item->option.argInfo = POPT_ARGFLAG_DOC_HIDDEN; 01101 item->option.arg = 0; 01102 item->option.val = 0; 01103 item->option.descrip = NULL; 01104 item->option.argDescrip = NULL; 01105 item->argc = alias.argc; 01106 item->argv = alias.argv; 01107 return poptAddItem(con, item, 0); 01108 }
int poptAddItem | ( | poptContext | con, | |
poptItem | newItem, | |||
int | flags | |||
) |
Add alias/exec item to context.
con | context | |
newItem | alias/exec item to add | |
flags | 0 for alias, 1 for exec |
参照先 poptContext_s::aliases・poptOption::arg・poptItem_s::argc・poptOption::argDescrip・poptOption::argInfo・poptItem_s::argv・poptOption::descrip・poptContext_s::execs・poptOption::longName・poptContext_s::numAliases・poptContext_s::numExecs・poptItem_s::option・poptOption::shortName・poptOption::val・xstrdup().
参照元 poptAddAlias().
01113 { 01114 poptItem * items, item; 01115 int * nitems; 01116 01117 switch (flags) { 01118 case 1: 01119 items = &con->execs; 01120 nitems = &con->numExecs; 01121 break; 01122 case 0: 01123 items = &con->aliases; 01124 nitems = &con->numAliases; 01125 break; 01126 default: 01127 return 1; 01128 /*@notreached@*/ break; 01129 } 01130 01131 *items = (poptItem)realloc((*items), ((*nitems) + 1) * sizeof(**items)); 01132 if ((*items) == NULL) 01133 return 1; 01134 01135 item = (*items) + (*nitems); 01136 01137 item->option.longName = 01138 (newItem->option.longName ? xstrdup(newItem->option.longName) : NULL); 01139 item->option.shortName = newItem->option.shortName; 01140 item->option.argInfo = newItem->option.argInfo; 01141 item->option.arg = newItem->option.arg; 01142 item->option.val = newItem->option.val; 01143 item->option.descrip = 01144 (newItem->option.descrip ? xstrdup(newItem->option.descrip) : NULL); 01145 item->option.argDescrip = 01146 (newItem->option.argDescrip ? xstrdup(newItem->option.argDescrip) : NULL); 01147 item->argc = newItem->argc; 01148 item->argv = newItem->argv; 01149 01150 (*nitems)++; 01151 01152 return 0; 01153 }
const char* poptBadOption | ( | poptContext | con, | |
int | flags | |||
) |
Return the option which caused the most recent error.
con | context | |
flags |
参照先 optionStackEntry::argv・optionStackEntry::next・poptContext_s::optionStack・poptContext_s::os.
参照元 main()・rpc_reg_shutdown_internals().
01158 { 01159 struct optionStackEntry * os = NULL; 01160 01161 if (con != NULL) 01162 os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os; 01163 01164 /*@-nullderef@*/ /* LCL: os->argv != NULL */ 01165 return (os && os->argv ? os->argv[os->next - 1] : NULL); 01166 /*@=nullderef@*/ 01167 }
const char* poptStrerror | ( | const int | error | ) |
Return formatted error string for popt failure.
error | popt error |
参照先 errno・strerror().
参照元 main()・net_rpc_shell()・process_cmd()・rpc_reg_shutdown_internals().
01170 { 01171 switch (error) { 01172 case POPT_ERROR_NOARG: 01173 return POPT_("missing argument"); 01174 case POPT_ERROR_BADOPT: 01175 return POPT_("unknown option"); 01176 case POPT_ERROR_BADOPERATION: 01177 return POPT_("mutually exclusive logical operations requested"); 01178 case POPT_ERROR_NULLARG: 01179 return POPT_("opt->arg should not be NULL"); 01180 case POPT_ERROR_OPTSTOODEEP: 01181 return POPT_("aliases nested too deeply"); 01182 case POPT_ERROR_BADQUOTE: 01183 return POPT_("error in parameter quoting"); 01184 case POPT_ERROR_BADNUMBER: 01185 return POPT_("invalid numeric value"); 01186 case POPT_ERROR_OVERFLOW: 01187 return POPT_("number too large or too small"); 01188 case POPT_ERROR_MALLOC: 01189 return POPT_("memory allocation failed"); 01190 case POPT_ERROR_ERRNO: 01191 return strerror(errno); 01192 default: 01193 return POPT_("unknown error"); 01194 } 01195 }
int poptStuffArgs | ( | poptContext | con, | |
const char ** | argv | |||
) |
Add arguments to context.
con | context | |
argv | argument array, NULL terminated |
参照先 optionStackEntry::argb・optionStackEntry::argc・optionStackEntry::argv・optionStackEntry::currAlias・optionStackEntry::next・optionStackEntry::nextArg・optionStackEntry::nextCharArg・poptContext_s::optionStack・poptContext_s::os・poptDupArgv()・optionStackEntry::stuffed.
01198 { 01199 int argc; 01200 int rc; 01201 01202 if ((con->os - con->optionStack) == POPT_OPTION_DEPTH) 01203 return POPT_ERROR_OPTSTOODEEP; 01204 01205 for (argc = 0; argv[argc]; argc++) 01206 {}; 01207 01208 con->os++; 01209 con->os->next = 0; 01210 con->os->nextArg = NULL; 01211 con->os->nextCharArg = NULL; 01212 con->os->currAlias = NULL; 01213 rc = poptDupArgv(argc, argv, &con->os->argc, &con->os->argv); 01214 con->os->argb = NULL; 01215 con->os->stuffed = 1; 01216 01217 return rc; 01218 }
const char* poptGetInvocationName | ( | poptContext | con | ) |
Return argv[0] from context.
con | context |
参照先 optionStackEntry::argv・poptContext_s::os.
参照元 set_logfile().
int poptStrippedArgv | ( | poptContext | con, | |
int | argc, | |||
char ** | argv | |||
) |
Shuffle argv pointers to remove stripped args, returns new argc.
con | context | |
argc | no. of args | |
argv | arg vector |
01227 { 01228 int numargs = argc; 01229 int j = 1; 01230 int i; 01231 01232 /*@-sizeoftype@*/ 01233 if (con->arg_strip) 01234 for (i = 1; i < argc; i++) { 01235 if (PBM_ISSET(i, con->arg_strip)) 01236 numargs--; 01237 } 01238 01239 for (i = 1; i < argc; i++) { 01240 if (con->arg_strip && PBM_ISSET(i, con->arg_strip)) 01241 continue; 01242 argv[j] = (j < numargs) ? argv[i] : NULL; 01243 j++; 01244 } 01245 /*@=sizeoftype@*/ 01246 01247 return numargs; 01248 }
int _popt_debug = 0 |