#! /usr/bin/awk -f # # Author: Chris Karakas # http://www.karakas-online.de # # Part of the LyX-to-X project. # See http://www.karakas-online.de/mySGML/ for a detailed # description. # # Copyright (c) 2004, Chris Karakas # http://www.karakas-online.de # chris at mydomain dot de (see above for my domain) # # This program 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, 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; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. # Inserts index entries in a LyX file for all items read from a # third file. Example of use: # # awkscr_insert_index_items indexitems - < EN-Book-noindexitems.lyx > EN-Book-indexitems.lyx # # indexitems: A file that contains the index entries (words), one per line # EN-Book-noindexitems.lyx: The file without index entries # EN-Book-indexitems.lyx: The file with index entries # # The "-" is important on the command line call, # see Chapter 8.4.3 ("A Glossary Lookup Script") of "sed & awk" # # To create a file without index entries, like EN-Book-noindexitems.lyx above, from one that # contains some, use the sedscr_delete_index_items script: # # sedscr_delete_index_items EN-Book.lyx > EN-Book-noindexitems.lyx # # To get a list of all index entries in a LyX file, use sedscr_list_index_items script: # # sedscr_list_index_items EN-Book.lyx > indexitems # Set input field separator to semicolon. BEGIN { FS = ";"; layout = ""; inset = 0; } # Read index items into an associative array named "index". # The index items are held, one per line, in the indexitems file. FILENAME == "indexitems" { n++ indexentry[$1] = $1 next } # /\\begin_inset/,/\\end_inset/ { print; next } /\\SpecialChar/ { print; next } /\\series/ { print; next } /\\emph/ { print; next } /\\shape/ { print; next } /\\begin_inset/ { inset += 1; print; next } /\\end_inset/ { inset -= 1; print; next } layout == "" { layout = "Preample"; print; next } /\\layout Title/ { layout = "Title"; print; next } /\\layout SGML/ { layout = "SGML"; print; next } /\\layout Chapter/ { layout = "Chapter"; print; next } /\\layout Section/ { layout = "Section"; print; next } /\\layout Subsection/ { layout = "Subsection"; print; next } /\\layout Subsubsection/ { layout = "Subsubsection"; print; next } /\\layout Standard/ { layout = "Standard"; print; next } /\\layout Code/ { layout = "Code"; print; next } /\\layout Itemize/ { layout = "Itemize"; print; next } /\\layout Enumerate/ { layout = "Enumerate"; print; next } /\\layout Quotation/ { layout = "Quotation"; print; next } /\\layout Abstract/ { layout = "Abstract"; print; next } /\\layout Description/ { layout = "Description"; print; next } /\\layout Comment/ { layout = "Comment"; print; next } /\\layout Caption/ { layout = "Caption"; print; next } /\\layout Part/ { layout = "Part"; print; next } /\\layout Paragraph/ { layout = "Paragraph"; print; next } /\\layout Subparagraph/ { layout = "Subparagraph"; print; next } /\\layout Author/ { layout = "Author"; print; next } /\\layout Date/ { layout = "Date"; print; next } /\\layout Authorgroup/ { layout = "Authorgroup"; print; next } /\\layout FirstName/ { layout = "FirstName"; print; next } /\\layout Surname/ { layout = "Surname"; print; next } /\\layout RevisionHistory/ { layout = "RevisionHistory"; print; next } /\\layout Revision/ { layout = "Revision"; print; next } /\\layout RevisionRemark/ { layout = "RevisionRemark"; print; next } /\\layout Literal/ { layout = "Literal"; print; next } { if ( ( layout == "Standard" || layout == "Itemize" || layout == "Enumerate" || layout == "Quotation" || layout == "Description" ) && ( inset == 0 ) ) { for (item in indexentry) { if (gsub(" " item " "," " item " \n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } else if (gsub("^" item " "," " item " \n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } else if (gsub(" " item "$"," " item "\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } else if (gsub(" " item ":"," " item ":\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } else if (gsub(" " item "\\."," " item ".\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } else if (gsub(" " item ","," " item ",\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } else if (gsub(" " item "\\?"," " item "?\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } else if (gsub(" " item ";"," " item ";\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } else if (gsub(" " item "\n"," " item "\n\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } else if (gsub(" " "\"" item "\""," " "\"" item "\"\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { continue } } { print; next } } } # Uncomment for testing purposes (and comment the other print statement): # {print "--->" layout " inset= " inset"<--- " $0} {print}