[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [GNUnet-developers] Textui stuff
From: |
Blake Matheny |
Subject: |
Re: [GNUnet-developers] Textui stuff |
Date: |
Sun, 17 Mar 2002 16:17:39 -0500 |
User-agent: |
Mutt/1.3.27i |
You might want to check out the source code for the file(1) utility. It uses a
pretty simple (but effective) method of examing the header of a file and
determining a type from there. A simple method to do this is to grab the hex of
the files header, and compare it with the existing magic file (typically
/usr/share/misc/magic. Example:
[duke 10] matheny > file textutils-2.0.tar.gz
textutils-2.0.tar.gz: gzip compressed data
[duke 11] matheny > hexdump -c textutils-2.0.tar.gz | head -1
0000000 037 213 \b \0 025 L « 7 002 003 ì < k s 033 7
[duke 12] misc > grep "gzip compressed data" /usr/share/misc/magic
0 string \037\213 gzip compressed data
As you can see, the hexdump matches the definition from /usr/share/misc/magic.
For the several file types I tried this always work. I think it would be pretty
simple to hack this out. Anyone see anything wrong with this method?
-Blake
Whatchu talkin' 'bout, Willis?
> Sunday has rolled around, and I'm bored.
>
> I started thinking about the textui a little bit and about how there is a
> special handler for inserting mp3 files. That got me thinking about
> scalibility, so instead of working on a curses ui I decided to work on
> automatic keywording instead.
>
> Basically the idea that I'm working on is to keep a linked list along the
> lines of:
>
> struct hand_l {
> char *t_mime; //the "text" in "text/html"
> char *b_mime; //the "html" in "text/html"
> int *function; //pointer to function that handles
> keywords
>
> //for this mime type
> struct hand_l* next; //the next node
> }
>
> The idea is that a function can register itself for handling the finding
> of keywords for a particular file type so that keywords can be figured out
> for more than just mp3s. Eventually with this idea, one will be able to
> call char * makekeywords(char *filename), which will return a space
> seperated list of keywords for any given file.
>
> I haven't figured out yet how to automatically determine the mime type of
> a file, though I assume that somewhere out there a library exists that
> takes a filename in, and returns the mime type.
>
> Why do I think doing this automatic keyword building is important? People
> are lazy. Actually, people are *really* lazy. So lazy that I suspect a lot
> of people would rarely bother to enter keywords. Having gnunet figure out
> keywords automatically would mitigate this problem.
>
> By the way, I use vi with tab spaces set to three (in vi :set ts=3)
>
>
>
> --
> GnuPG fingerprint AAE4 8C76 58DA 5902 761D 247A 8A55 DA73 0635 7400
> James Blackwell -- Director http://www.linuxguru.net
--
Blake Matheny
address@hidden
PGP-Key http://www.dbaseiv.net/purdue.key