/* File: file_txt.c Copyright (C) 2005-2012 Christophe GRENIER This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_txt) #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_TIME_H #include #endif #include /* tolower */ #include #include #include "types.h" #include "common.h" #include "filegen.h" #include "log.h" #include "memmem.h" #include "utfsize.h" #if defined(__FRAMAC__) #include "__fc_builtin.h" #endif #if !defined(MAIN_txt) && !defined(SINGLE_FORMAT) extern const file_hint_t file_hint_doc; extern const file_hint_t file_hint_jpg; extern const file_hint_t file_hint_pdf; extern const file_hint_t file_hint_sld; extern const file_hint_t file_hint_tiff; extern const file_hint_t file_hint_zip; #endif typedef struct { const char *string; const unsigned int len; const char *extension; } txt_header_t; /*@ requires valid_register_header_check(file_stat); */ static void register_header_check_fasttxt(file_stat_t *file_stat); /*@ requires valid_register_header_check(file_stat); */ static void register_header_check_snz(file_stat_t *file_stat); /*@ requires valid_register_header_check(file_stat); */ static void register_header_check_txt(file_stat_t *file_stat); static const char *extension_asp="asp"; static const char *extension_bat="bat"; static const char *extension_c="c"; static const char *extension_csv="csv"; static const char *extension_cdxml="cdxml"; static const char *extension_dc="dc"; static const char *extension_emlx="emlx"; static const char *extension_ers="ers"; static const char *extension_f="f"; static const char *extension_fb2="fb2"; static const char *extension_fods="fods"; static const char *extension_fst="fst"; static const char *extension_gcs="gcs"; static const char *extension_ghx="ghx"; static const char *extension_go="go"; static const char *extension_gpx="gpx"; static const char *extension_groovy="groovy"; static const char *extension_gsb="gsb"; static const char *extension_h="h"; #ifdef DJGPP static const char *extension_html="htm"; #else static const char *extension_html="html"; #endif static const char *extension_ics="ics"; static const char *extension_inf="inf"; static const char *extension_ini="ini"; #ifdef DJGPP static const char *extension_java="jav"; #else static const char *extension_java="java"; #endif static const char *extension_json="json"; static const char *extension_jsp="jsp"; static const char *extension_ldif="ldif"; static const char *extension_ly="ly"; static const char *extension_mbox="mbox"; static const char *extension_mol2="mol2"; static const char *extension_php="php"; static const char *extension_pl="pl"; #ifdef DJGPP static const char *extension_plist="pli"; #else static const char *extension_plist="plist"; #endif static const char *extension_pm="pm"; static const char *extension_prproj="prproj"; static const char *extension_py="py"; static const char *extension_rb="rb"; static const char *extension_rtf="rtf"; static const char *extension_sla="sla"; static const char *extension_smil="smil"; static const char *extension_stl="stl"; static const char *extension_svg="svg"; static const char *extension_ttd="ttd"; static const char *extension_tex="tex"; #ifdef UTF16 static const char *extension_utf16="utf16"; #endif static const char *extension_vb="vb"; static const char *extension_vbm="vbm"; static const char *extension_vcf="vcf"; static const char *extension_xml="xml"; static const char *extension_xmp="xmp"; const file_hint_t file_hint_fasttxt= { .extension="tx?", .description="Text files with header: rtf,xml,xhtml,mbox/imm,pm,ram,reg,sh,slk,stp,jad,url", .max_filesize=PHOTOREC_MAX_FILE_SIZE, .recover=1, .enable_by_default=1, .register_header_check=®ister_header_check_fasttxt }; const file_hint_t file_hint_snz= { .extension="snz", .description="Olfaction SeeNez odorama", .max_filesize=PHOTOREC_MAX_FILE_SIZE, .recover=1, .enable_by_default=1, .register_header_check=®ister_header_check_snz }; const file_hint_t file_hint_txt= { .extension="txt", .description="Other text files: txt,html,asp,bat,C,jsp,perl,php,py/emlx... scripts", .max_filesize=PHOTOREC_MAX_FILE_SIZE, .recover=1, .enable_by_default=1, .register_header_check=®ister_header_check_txt }; static unsigned char ascii_char[256]; static const txt_header_t fasttxt_headers[] = { /* Unix shell */ { "#!/bin/bash", 11, "sh"}, { "#!/bin/ksh", 10, "sh"}, #ifndef DISABLED_FOR_FRAMAC { "#!/bin/sh", 9, "sh"}, { "#! /bin/bash", 12, "sh"}, { "#! /bin/ksh", 11, "sh"}, { "#! /bin/sh", 10, "sh"}, { "#!/usr/bin/env groovy", 21, "groovy"}, { "#!/usr/bin/env perl", 19, "pl"}, { "#!/usr/bin/env php", 18, "php"}, { "#!/usr/bin/env python", 21, "py"}, { "#!/usr/bin/env ruby", 19, "rb"}, /* Opera Hotlist bookmark/contact list/notes */ { "Opera Hotlist version 2.0", 25, "adr"}, /* Microsoft VB Class module */ { "VERSION 1.0 CLASS\r\nBEGIN", 24, "cls"}, /* Cue sheet often begins by the music genre * or by the filename * http://wiki.hydrogenaudio.org/index.php?title=Cue_sheet */ { "REM GENRE ", 10, "cue"}, { "FILE \"", 6, "cue"}, /* Lotus Data Interchange Format */ { "TABLE\r\n0,1\r\n", 12, "dif"}, /* Designer, a Photobook Designer Software */ { "vSg4q7j8GLrtf", 13, "dp"}, { "-----BEGIN DSA PRIVATE KEY-----", 31, "dsa"}, /* EMKA IOX file */ { "1\t\t\t\t\tthis file\t", 16, #ifdef DJGPP "emk" #else "emka" #endif }, /* Source code in go language */ { "package main", 12, "go"}, /* ENVI */ { "ENVI\r\ndescription", 17, "hdr"}, /* Java Application Descriptor * http://en.wikipedia.org/wiki/JAD_%28file_format%29 */ { "MIDlet-1:", 9, "jad"}, { "{\"title\":\"\",\"id\":1,\"dateAdded\":", 31, "json"}, { "-----BEGIN RSA PRIVATE KEY-----", 31, "key"}, /* Lyx http://www.lyx.org */ { "#LyX 1.", 7, "lyx"}, { "#LyX 2.", 7, "lyx"}, /* LilyPond http://lilypond.org*/ { "\n\\version \"", 11, "ly"}, /* Moving Picture Experts Group Audio Layer 3 Uniform Resource Locator */ { "#EXTM3U", 7, "m3u"}, /* http://www.mnemosyne-proj.org/ * flash-card program to help you memorise question/answer pairs */ { "--- Mnemosyne Data Base --- Format Version 2 ---", 48, "mem"}, /* Mozilla, firefox, thunderbird msf (Mail Summary File) */ { "//