Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
.hidden files and ls
Results 1 to 7 of 7

Thread: .hidden files and ls

Hybrid View

  1. #1

    .hidden files and ls

    Hi! I wrote the hack below in C++ to get ls to recognize ".hidden" files (files that list directory entries to be removed from the listing ala MacOS X). I even shoehorned it into ls and added "-lstdc++ hidden.o" to coreutils' Makefile. However, I'd much rather use C instead of C++ and plop the code into ls.c itself (and not depend on the standard C++ library). I don't know the first thing about memory management C, so I was hoping someone here knew the equivalent C code (or could direct me to where I could find out). Thanks!

    Code:
    // hidden.h
    #ifndef HIDDEN_FILE_H
    #define HIDDEN_FILE_H
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    void load_hidden_file(const char* a_dir);
    int is_hidden(const char* a_entry);
    void release_hidden_files();
    #ifdef __cplusplus
    }
    #endif
    
    #endif // HIDDEN_FILE_H
    
    // hidden.cpp
    #include <algorithm>
    #include <fstream>
    #include <string>
    #include <vector>
    #include "hidden.h"
    
    namespace {
    std::vector<std::string> hidden;
    }
    
    void load_hidden_file(const char* a_dir) {
    std::string line = a_dir + std::string("/.hidden");
    std::ifstream file(line.c_str());
    if (file)
    while(std::getline(file, line))
    hidden.push_back(line);
    file.close();
    }
    
    int is_hidden(const char* a_entry) {
    return (std::find(hidden.begin(), hidden.end(), a_entry) != hidden.end())
    || (a_entry[0] == '.');
    }
    
    void release_hidden_files() {
    hidden.clear();
    }

  2. #2

    Re:.hidden files and ls

    Not to be a killjoy, but doesn't the -a option take care of this?

  3. #3

    Re:.hidden files and ls

    Good work anshelm!!!

    Yes, this can be done with 'ls -a' but it was a good project none the less. You might use that source elsewhere with an app to see the hidden files. Dunno.

  4. #4

    Re:.hidden files and ls

    I don't think I was quite clear on my intent.

    I'm extending the functionaility of hidden files. This will allow you to put a file called ".hidden" in a directory and list files you don't want listed. So instead of renaming "bin" to ".bin", you could add "bin" to the .hidden file and it will have the same effect (such as appearing when -a is used).

  5. #5

    Re:.hidden files and ls

    Oh, now that is useful.

  6. #6

    Re:.hidden files and ls

    Very nice.

    For the sake of interest you may want to browse the source for nautilus, the Gnome file manager...I believe it does largely the same thing but in a graphical way.

  7. #7

    Re:.hidden files and ls

    I poked around in the code for Nautilus, but the function for adding support for ".hidden" depends on several functions that appear to be from gnome, as well as is quite integrated with the rest of Nautilus's view of the current directory. So instead I took a shot at porting to C based solely on the info I could find on google. I'm pretty sure I made some mistakes in regards to memory management alone, although it does compile and work. Any improvements or pointers to what I did wrong would be appreciated.

    Code:
    static char** hidden_file_lines;
    static long int hidden_file_count;
    
    static void load_hidden_file(const char* a_dir) {
    char* name;
    FILE* fp;
    char line[PATH_MAX];
    
    hidden_file_count = 0;
    hidden_file_lines = (char**)malloc(hidden_file_count * sizeof(char*));
    
    name = (char*)malloc((strlen(a_dir) + 9) * sizeof(char));
    name = strcpy(name, a_dir);
    name = strcat(name, "/.hidden");
    
    if ((fp = fopen(name, "r")) != NULL) {
    while (fgets(line, PATH_MAX, fp) != NULL) {
    if (strlen(line) == 1) continue;
    
    hidden_file_count++;
    hidden_file_lines =
    (char**)realloc((void*)hidden_file_lines,
    hidden_file_count * sizeof(char*));
    
    hidden_file_lines[hidden_file_count - 1] =
    (char*)calloc(strlen(line) - 1, sizeof(char));
    hidden_file_lines[hidden_file_count - 1] =
    memcpy(hidden_file_lines[hidden_file_count - 1],
    line, (strlen(line) - 1));
    }
    }
    fclose(fp);
    free(name);
    return;
    }
    
    static int is_hidden(const char* a_entry) {
    long int i;
    
    if (a_entry[0] == '.') {
    return 1;
    }
    
    for (i = 0; i < hidden_file_count; i++) {
    if (strcmp(a_entry, hidden_file_lines[i]) == 0) {
    return 1;
    }
    }
    
    return 0;
    }
    
    static void release_hidden_file() {
    long int i;
    for (i = 0; i < hidden_file_count; i++) {
    free(hidden_file_lines[i]);
    }
    free(hidden_file_lines);
    hidden_file_count = 0;
    }

Similar Threads

  1. Hidden M$ files
    By KenHan in forum General Chat
    Replies: 2
    Last Post: 11-25-2002, 12:30 AM
  2. zip files
    By friskydrifter in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 11-24-2002, 09:20 PM
  3. FTP into home dir.  hidden files visible/editable
    By Blaqb0x in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 05-19-2002, 05:16 AM
  4. .c files
    By elovkoff in forum Linux - Hardware, Networking & Security
    Replies: 2
    Last Post: 05-16-2002, 07:06 PM
  5. Hidden trackers in file share software
    By JimH in forum General Chat
    Replies: 0
    Last Post: 01-05-2002, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •