[cfe-commits] r86566 - /cfe/trunk/tools/c-index-test/c-index-test.c
Ted Kremenek
kremenek at apple.com
Mon Nov 9 10:31:03 PST 2009
Should we just have c-index-test.c be written in C++ and have it use
the CommandLine library?
On Nov 9, 2009, at 10:19 AM, Douglas Gregor wrote:
> Author: dgregor
> Date: Mon Nov 9 12:19:57 2009
> New Revision: 86566
>
> URL: http://llvm.org/viewvc/llvm-project?rev=86566&view=rev
> Log:
> Improve c-index-test's parsing of the -code-completion-
> at=file:line:column argument
>
> Modified:
> cfe/trunk/tools/c-index-test/c-index-test.c
>
> Modified: cfe/trunk/tools/c-index-test/c-index-test.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=86566&r1=86565&r2=86566&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/tools/c-index-test/c-index-test.c (original)
> +++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Nov 9 12:19:57
> 2009
> @@ -113,38 +113,41 @@
> memory (that will be owned by the caller) to store the file name.
> */
> int parse_file_line_column(const char *input, char **filename,
> unsigned *line,
> unsigned *column) {
> - const char *colon = strchr(input, ':');
> + /* Find the second colon. */
> + const char *second_colon = strrchr(input, ':'), *first_colon;
> char *endptr = 0;
> - if (!colon) {
> + if (!second_colon || second_colon == input) {
> fprintf(stderr, "could not parse filename:line:column in
> '%s'\n", input);
> return 1;
> }
>
> - /* Copy the file name. */
> - *filename = (char*)malloc(colon - input);
> - strncpy(*filename, input, colon - input);
> - (*filename)[colon - input] = 0;
> - input = colon + 1;
> -
> - /* Parse the line number. */
> - *line = strtol(input, &endptr, 10);
> - if (*endptr != ':') {
> - fprintf(stderr, "could not parse line:column in '%s'\n", input);
> - free(filename);
> - *filename = 0;
> - return 1;
> - }
> - input = endptr + 1;
> -
> /* Parse the column number. */
> - *column = strtol(input, &endptr, 10);
> + *column = strtol(second_colon + 1, &endptr, 10);
> if (*endptr != 0) {
> fprintf(stderr, "could not parse column in '%s'\n", input);
> - free(filename);
> - *filename = 0;
> + return 1;
> + }
> +
> + /* Find the first colon. */
> + first_colon = second_colon - 1;
> + while (first_colon != input && *first_colon != ':')
> + --first_colon;
> + if (first_colon == input) {
> + fprintf(stderr, "could not parse line in '%s'\n", input);
> + return 1;
> + }
> +
> + /* Parse the line number. */
> + *line = strtol(first_colon + 1, &endptr, 10);
> + if (*endptr != ':') {
> + fprintf(stderr, "could not parse line in '%s'\n", input);
> return 1;
> }
>
> + /* Copy the file name. */
> + *filename = (char*)malloc(first_colon - input + 1);
> + memcpy(*filename, input, first_colon - input);
> + (*filename)[first_colon - input] = 0;
> return 0;
> }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list