Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Initial work on unified "--" flag support, as requested in https://fossil-scm.org/forum/forumpost/64acc6b653. There's still lots to do here. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | double-dash-flag |
Files: | files | file ages | folders |
SHA3-256: |
d8ebbd76cc9ae94b6f9ffb8ef6856b3a |
User & Date: | stephan 2019-09-27 08:48:57 |
Context
2019-09-27
| ||
09:55 | Simplified the verify_all_options() porting strategy, such that -- is disallowed by default and routines which should/can support it need to call verify_all_options2() instead of us changing the signature of verify_all_options(). This will result in far fewer changes than the previous approach. ... (check-in: a9b9b5bc user: stephan tags: double-dash-flag) | |
08:48 | Initial work on unified "--" flag support, as requested in https://fossil-scm.org/forum/forumpost/64acc6b653. There's still lots to do here. ... (check-in: d8ebbd76 user: stephan tags: double-dash-flag) | |
2019-09-26
| ||
17:58 | Remove the discussion of the "close" command from the fiveminutes.wiki document as the "close" command is not really needed, is rarely used, and serves no purpose in the document but to confuse the reader. ... (check-in: f6e63530 user: drh tags: trunk) | |
Changes
Changes to src/main.c.
︙ | ︙ | |||
898 899 900 901 902 903 904 | g.argv[i] = g.argv[j]; } g.argc = i; } /* | | > > | > > > > | > > > | > > > | | 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 | g.argv[i] = g.argv[j]; } g.argc = i; } /* ** Look for a command-line option. If present, remove it from the ** argument list and return a pointer to either the flag's name (if ** hasArg==0), sans leading - or --, or its value (if hasArg==1). ** Return NULL if the flag is not found. ** ** zLong is the "long" form of the flag and zShort is the ** short/abbreviated form (typically a single letter, but it may be ** longer). zLong must not be NULL, but zShort may be. ** ** hasArg==0 means the option is a flag. It is either present or not. ** hasArg==1 means the option has an argument, in which case a pointer ** to the argument's value is returned. For zLong, a flag value (if ** hasValue==1) may either be in the form (--flag=value) or (--flag ** value). For zShort, only the latter form is accepted. ** ** If a standalone argument of "--" is encountered in the argument ** list while searching for the given flag(s), this routine stops ** searching and NULL is returned. */ const char *find_option(const char *zLong, const char *zShort, int hasArg){ int i; int nLong; const char *zReturn = 0; assert( hasArg==0 || hasArg==1 ); nLong = strlen(zLong); for(i=1; i<g.argc; i++){ char *z; if( i+hasArg >= g.argc ) break; z = g.argv[i]; if( z[0]!='-' ) continue; z++; if( z[0]=='-' ){ if( z[1]==0 ){ /* Stop processing at "--" */ break; } z++; } if( strncmp(z,zLong,nLong)==0 ){ if( hasArg && z[nLong]=='=' ){ zReturn = &z[nLong+1]; |
︙ | ︙ | |||
953 954 955 956 957 958 959 | int has_option(const char *zOption){ int i; int n = (int)strlen(zOption); for(i=1; i<g.argc; i++){ char *z = g.argv[i]; if( z[0]!='-' ) continue; z++; | | > > > > > > | > > > | 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | int has_option(const char *zOption){ int i; int n = (int)strlen(zOption); for(i=1; i<g.argc; i++){ char *z = g.argv[i]; if( z[0]!='-' ) continue; z++; if( z[0]=='-' ){ z++; if( z[0]==0 ){ /* Stop searching at "--" */ break; } } if( strncmp(z,zOption,n)==0 && (z[n]==0 || z[n]=='=') ) return 1; } return 0; } /* ** Look for multiple occurrences of a command-line option with the ** corresponding argument. ** ** Return a malloc allocated array of pointers to the arguments. ** ** pnUsedArgs is used to store the number of matched arguments. ** ** Caller is responsible for freeing allocated memory by passing the ** head of the array (not each entry) to fossil_free(). (The ** individual entries have the same lifetime as values returned from ** find_option().) */ const char **find_repeatable_option( const char *zLong, const char *zShort, int *pnUsedArgs ){ const char *zOption; |
︙ | ︙ | |||
1011 1012 1013 1014 1015 1016 1017 1018 | return g.zRepositoryOption; } /* ** Verify that there are no unprocessed command-line options. If ** Any remaining command-line argument begins with "-" print ** an error message and quit. */ | > > > > > > > > > > > > > > > | > | > > > > > > > > > > | | | > > > > | 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 | return g.zRepositoryOption; } /* ** Verify that there are no unprocessed command-line options. If ** Any remaining command-line argument begins with "-" print ** an error message and quit. ** ** If fAllowDoubleDash is true then if the flag "--" is found, it is ** removed from the list and arguments after that flag are not ** inspected by this function (they are assumed to be filenames, even ** if they syntactically look like flags). If fAllowDoubleDash is ** false then the "--" flag will trigger a fatal error exactly as if ** an unprocessed flag were encountered. ** ** Sidebar: the question of whether fAllowDoubleDash should be true or ** false would seem to boil down to: does the calling routine ** expect/allow arbitrary file/page/branch/whatever name arguments ** after its required arguments? ** ** Once the "--" support is completed, this function will be renamed ** (back) to verify_all_options(). */ void verify_all_options_porting_crutch(int fAllowDoubleDash){ int i; for(i=1; i<g.argc; i++){ const char * arg = g.argv[i]; if( arg[0]=='-' ){ if( arg[1]=='-' && arg[2]==0 ){ if(fAllowDoubleDash){ /* Remove "--" from the list and assume any following ** arguments are file names. */ remove_from_argv(i, 1); break; }else{ fossil_fatal("The -- flag is not allowed here."); } }else if( arg[1]!=0 ){ fossil_fatal( "unrecognized command-line option, or missing argument: %s", arg); } } } } void verify_all_options(void){ verify_all_options_porting_crutch(0); } /* ** This function returns a human readable version string. */ const char *get_version(){ static const char version[] = RELEASE_VERSION " " MANIFEST_VERSION " " MANIFEST_DATE " UTC"; |
︙ | ︙ |