[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Recognising Symbolic Links under Windows XP
From: |
davin . pearson |
Subject: |
Recognising Symbolic Links under Windows XP |
Date: |
19 Jul 2005 02:43:57 -0700 |
User-agent: |
G2/0.2 |
To Richard Stallman and others...
I have been using Emacs for years and in my opinion it is something of
a religion!
I was recently using Emacs under Gnu/Linux where I learnt about
symbolic links and how useful they are.
These days I am mainly using Emacs under Windows XP so I wondered if
it was possible for Emacs to recognise Windows-style symbolic links
(*.lnk files)
The Cygwin shell and the Windows Explorer recognises *.lnk files so I
thought it would be a good thing if Emacs could be made to recognise
*.lnk files.
After a little bit of C++ and Lisp coding a came up with a solution.
All that you need is a C/C++ program that parses the *.lnk file and
returns via stdout the name of the file/directory that the link points
to.
Suppose that the name of the C/C++ program is d:/bin/lnk.exe.
Then the following snippet of Lisp code achieves the result of taking
you (inside Emacs) to the target of the *.lnk file:
The following code snippet is inside a "cond" form:
((string-match "\\.lnk$" filename)
(shell-command (concat "d:/bin/lnk.exe \"" filename "\""))
(setq buf (set-buffer "*Shell Command Output*"))
(goto-char (point-min))
(setq output (my-find--current-line))
(cond ((string-match "Usage:" output)
(message output))
((file-exists-p output)
(find-file output))
(t
(message "Cannot find file: %s" output)))
(kill-buffer buf))
This is all good for my own private purposes but I realise that for my
idea to be included in the standard Gnu Emacs that it must also be
robust.
I have no idea what the format of the *.lnk files is, and a robust
program would have to support all possible examples.
Here is the source code to my lnk.exe file:
> #include "../../2003/noio/io.hh"
>
> int main(int argc, char** argv)
> {
> const char* usage = "Usage: lnk FILENAME.LNK\n";
>
> if (argc != 2) {
> std::cout << usage;
> exit(EXIT_FAILURE);
> }
>
> const char* filename = argv[1];
> int len = strlen(filename);
>
> const char* last_four = filename + len - 1 - 4;
> if (0 == strcmp(last_four, ".lnk")) {
> std::cout << usage;
> exit(EXIT_FAILURE);
> }
>
> FILE* f = fopen(filename,"rb");
>
> string_buffer sb;
> int ch;
> while ((ch = fgetc(f)) != -1) {
> if ((ch >= 0x20) && (ch <= 0x7f)) {
> sb << (char)ch;
> }
> }
>
> int i = index_of(sb, ":\\") - 1;
>
> ASSERT(i != -1);
>
> string link = substring(sb, i, sb.get_length());
>
> cout << link << '\n';
>
> exit(EXIT_SUCCESS);
> }
> END_OF_MAIN();
>
Sorry about the usage of my non-standard I/O library, but it would not
be to hard to rewrite this code to use either C or C++ I/O libraries.
Please tell me if you think my idea is a good one!
-*-
P.S. Another idea for making Emacs better would be for dabbrev-expand
to search through the kill ring for possible completions.
Regards,
Davin Pearson http://www.davinpearson.com
- Recognising Symbolic Links under Windows XP,
davin . pearson <=