~ubuntu-branches/ubuntu/gutsy/slocate/gutsy

« back to all changes in this revision

Viewing changes to src/cmds.c

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Lindsay
  • Date: 2006-01-06 09:36:28 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060106093628-cq82c695r3st8xkv
Tags: 3.0.beta.r3-1
* The environment variable LOCATE_PATH was not being used properly. It will
  now be used the same as in v2.7. Closes: #345646
* slocate was returning non zero for -h, --help, -V and --version. It now
  returns zero.
* PRUNEFS was being ignored in /etc/updatedb.conf
* Added documentation describing how /etc/updatedb.conf is used and what
  is supported to the README and the slocate.1 and updatedb.1 man pages.
* README.debian was removed in 3.0.beta.r1-1 to close bug 272131, but it was
  accidently readded in 3.0.beta.r2-1. I now have a use for it, so it is now
  here to stay.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
        cmd_data->updatedb = FALSE;
43
43
        cmd_data->search_str = NULL;
44
44
        cmd_data->updatedb_conf = NULL;
 
45
        cmd_data->exit_but_nice = 0;
45
46
 
46
47
        return cmd_data;
47
48
        
136
137
               "   --version          - Display version.\n"
137
138
               "\n"
138
139
               "Author: Kevin Lindsay\n"
139
 
               "Bugs:   kevin@trakker.ca\n"
 
140
               "Bugs:   slocate@trakker.ca\n"
140
141
               "HTTP:   http://slocate.trakker.ca/\n"
141
142
               "\n");
142
143
}
271
272
 
272
273
        /* Make sure dblist is not empty */
273
274
        if (!dblist || strlen(dblist) == 0) {
274
 
                report_error(g_data, WARNING, "parse_userdb: database string is empty.\n");
 
275
                //report_error(g_data, WARNING, "parse_userdb: database string is empty.\n");
275
276
                goto EXIT;
276
277
        }
277
278
 
476
477
 
477
478
 
478
479
/* Parse Dash */
 
480
/* ret code: 0 - error
 
481
 *           1 - success
 
482
 *           2 - success but exit nicely */
479
483
int parse_dash(struct g_data_s *g_data, char *option)
480
484
{
481
485
        char *ptr = NULL;
501
505
 
502
506
        if (strcmp(uc_option, "HELP") == 0) {
503
507
                usage(g_data);
504
 
                ret = 0;
 
508
                ret = 2;
505
509
                goto EXIT;
506
510
        } else if (strcmp(uc_option, "VERSION") == 0) {
507
511
                printf("%s\n", SL_VERSION);
508
 
                ret = 0;
 
512
                ret = 2;
509
513
                goto EXIT;
510
514
        } else if (strcmp(uc_option, "VERBOSE") == 0) {
511
515
                g_data->VERBOSE = TRUE;
653
657
        }
654
658
        
655
659
        if (exclude_str) {
656
 
                if (0 && !parse_exclude(g_data, exclude_str))
 
660
                if (!parse_exclude(g_data, exclude_str))
657
661
                    goto EXIT;
658
662
        }
659
663
                
695
699
        int reg_ret = 0;
696
700
        char regex_errbuf[1024];
697
701
        char *ENV_locate_path = NULL;
698
 
 
699
 
        /* Parse environment variables */
700
 
        if ((ENV_locate_path = getenv("LOCATE_PATH"))) {
701
 
                if (!parse_userdb(g_data, getenv("LOCATE_PATH")))
702
 
                    goto EXIT;
703
 
        }
 
702
        int add_default_db = 1;
 
703
        int dash_ret = 0;
704
704
 
705
705
        if (!(cmd_data = init_cmd_data(g_data)))
706
706
            goto EXIT;
 
707
        
 
708
        if (strcmp(g_data->progname, "updatedb") == 0)
 
709
            cmd_data->updatedb = TRUE;
707
710
 
708
711
        while ((ch = getopt(argc,argv,"VvuhqU:r:o:e:l:d:-:n:f:c:i")) != EOF) {
709
712
                switch(ch) {
710
713
                        /* Help */
711
714
                 case 'h':
712
715
                        usage(g_data);
 
716
                        cmd_data->exit_but_nice = 1;
713
717
                        goto EXIT;
714
718
                        break;
715
719
                        /* Quiet Mode. Don't print warnings or errors. */
720
724
                        break;
721
725
                 case 'V':
722
726
                        printf("%s\n", SL_VERSION);
 
727
                        cmd_data->exit_but_nice = 1;
723
728
                        goto EXIT;
724
729
                        break;
725
730
                        /* Turn VERBOSE mode ON */
746
751
                        /* Index from the root '/' path */
747
752
                 case 'u':
748
753
                        cmd_data->updatedb = TRUE;
 
754
                        add_default_db = 0;
749
755
                        break;
750
756
 
751
757
                        /* Index from a specific path */
755
761
                        if (g_data->index_path)
756
762
                            free(g_data->index_path);
757
763
                        g_data->index_path = strdup(optarg);
 
764
                        add_default_db = 0;
758
765
                        break;
759
766
                 case 'c':
760
767
                        if (cmd_data->updatedb_conf)
770
777
                        
771
778
                        /* Specify the database to search in */
772
779
                 case 'd':
 
780
                        add_default_db = 0;
773
781
                        if (!parse_userdb(g_data, optarg))
774
782
                            goto EXIT;
775
783
                        break;
808
816
                            goto EXIT;
809
817
                        break;
810
818
                 case '-':
811
 
                        if (!parse_dash(g_data, optarg))
 
819
                        dash_ret = parse_dash(g_data, optarg);
 
820
                        if (!dash_ret)
812
821
                            goto EXIT;
 
822
                        else if (dash_ret == 2) {
 
823
                                cmd_data->exit_but_nice = 1;
 
824
                                goto EXIT;
 
825
                        }
813
826
                        break;
814
827
                 default:
815
828
                        break;
832
845
                        report_error(g_data, FATAL, "match: regular expression: %s\n", regex_errbuf);
833
846
                        goto EXIT;
834
847
                }
835
 
        }       
 
848
        }
 
849
 
 
850
        if (!cmd_data->updatedb) {
 
851
                /* Parse environment variables */
 
852
                if ((ENV_locate_path = getenv("LOCATE_PATH"))) {
 
853
                        if (!parse_userdb(g_data, getenv("LOCATE_PATH")))
 
854
                            goto EXIT;
 
855
                }
 
856
                
 
857
                if (add_default_db) {
 
858
                        if (!parse_userdb(g_data, DEFAULT_DB))
 
859
                            goto EXIT;
 
860
                }
 
861
        } else
 
862
            parse_updatedb(g_data, cmd_data->updatedb_conf);
836
863
 
837
864
        return cmd_data;
838
865
 
839
866
EXIT:
 
867
        if (cmd_data->exit_but_nice)
 
868
            return cmd_data;
 
869
        
840
870
        free_cmd_data(cmd_data);
841
871
        cmd_data = NULL;
842
872