From 7b358424ebad9349421acd533c2fa1cbf6cf3e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 28 Dec 2016 16:52:56 +0100 Subject: Initial import of xtrkcad version 1:4.0.2-2 --- app/tools/CMakeLists.txt | 18 + app/tools/HACKING | 35 + app/tools/addcrlf.c | 242 + app/tools/bin2c.c | 126 + app/tools/dirent.c | 145 + app/tools/dirent.h | 50 + app/tools/halibut/CMakeLists.txt | 32 + app/tools/halibut/LICENCE | 36 + app/tools/halibut/README | 36 + app/tools/halibut/biblio.c | 105 + app/tools/halibut/bk_html.c | 2791 ++++++ app/tools/halibut/bk_paper.c | 2789 ++++++ app/tools/halibut/charset/CMakeLists.txt | 38 + app/tools/halibut/charset/LICENCE | 22 + app/tools/halibut/charset/README | 37 + app/tools/halibut/charset/big5enc.c | 93 + app/tools/halibut/charset/big5set.c | 4045 +++++++++ app/tools/halibut/charset/charset.h | 229 + app/tools/halibut/charset/cns11643.c | 13104 +++++++++++++++++++++++++++++ app/tools/halibut/charset/cp949.c | 94 + app/tools/halibut/charset/cstable.c | 120 + app/tools/halibut/charset/enum.c | 28 + app/tools/halibut/charset/euc.c | 272 + app/tools/halibut/charset/fromucs.c | 82 + app/tools/halibut/charset/gb2312.c | 2089 +++++ app/tools/halibut/charset/hz.c | 142 + app/tools/halibut/charset/internal.h | 126 + app/tools/halibut/charset/iso2022.c | 1385 +++ app/tools/halibut/charset/iso2022s.c | 544 ++ app/tools/halibut/charset/istate.c | 3 + app/tools/halibut/charset/jisx0208.c | 2021 +++++ app/tools/halibut/charset/jisx0212.c | 1919 +++++ app/tools/halibut/charset/ksx1001.c | 5261 ++++++++++++ app/tools/halibut/charset/locale.c | 93 + app/tools/halibut/charset/localenc.c | 174 + app/tools/halibut/charset/macenc.c | 169 + app/tools/halibut/charset/mimeenc.c | 333 + app/tools/halibut/charset/sbcs.c | 72 + app/tools/halibut/charset/sbcsdat.c | 4485 ++++++++++ app/tools/halibut/charset/sbcsdat.h | 75 + app/tools/halibut/charset/shiftjis.c | 128 + app/tools/halibut/charset/slookup.c | 29 + app/tools/halibut/charset/superset.c | 65 + app/tools/halibut/charset/test.c | 72 + app/tools/halibut/charset/toucs.c | 87 + app/tools/halibut/charset/utf16.c | 217 + app/tools/halibut/charset/utf7.c | 295 + app/tools/halibut/charset/utf8.c | 907 ++ app/tools/halibut/charset/xenc.c | 95 + app/tools/halibut/contents.c | 244 + app/tools/halibut/deflate.c | 2781 ++++++ app/tools/halibut/deflate.h | 168 + app/tools/halibut/error.c | 378 + app/tools/halibut/halibut.h | 548 ++ app/tools/halibut/help.c | 56 + app/tools/halibut/in_afm.c | 276 + app/tools/halibut/in_pf.c | 450 + app/tools/halibut/index.c | 270 + app/tools/halibut/input.c | 1644 ++++ app/tools/halibut/keywords.c | 154 + app/tools/halibut/licence.c | 51 + app/tools/halibut/main.c | 473 ++ app/tools/halibut/malloc.c | 149 + app/tools/halibut/misc.c | 580 ++ app/tools/halibut/paper.h | 405 + app/tools/halibut/psdata.c | 4523 ++++++++++ app/tools/halibut/tree234.c | 2197 +++++ app/tools/halibut/tree234.h | 202 + app/tools/halibut/ustring.c | 486 ++ app/tools/halibut/version | 1 + app/tools/halibut/version.c | 13 + app/tools/halibut/wcwidth.c | 184 + app/tools/listxtp.c | 191 + app/tools/oldscripts/README | 4 + app/tools/oldscripts/checkall | 10 + app/tools/oldscripts/diffall | 37 + app/tools/oldscripts/fetchall | 46 + app/tools/oldscripts/makeall | 23 + app/tools/oldscripts/markall | 17 + app/tools/oldscripts/mkwinrlse | 34 + app/tools/oldscripts/roall | 22 + 81 files changed, 61972 insertions(+) create mode 100644 app/tools/CMakeLists.txt create mode 100644 app/tools/HACKING create mode 100644 app/tools/addcrlf.c create mode 100644 app/tools/bin2c.c create mode 100644 app/tools/dirent.c create mode 100644 app/tools/dirent.h create mode 100644 app/tools/halibut/CMakeLists.txt create mode 100644 app/tools/halibut/LICENCE create mode 100644 app/tools/halibut/README create mode 100644 app/tools/halibut/biblio.c create mode 100644 app/tools/halibut/bk_html.c create mode 100644 app/tools/halibut/bk_paper.c create mode 100644 app/tools/halibut/charset/CMakeLists.txt create mode 100644 app/tools/halibut/charset/LICENCE create mode 100644 app/tools/halibut/charset/README create mode 100644 app/tools/halibut/charset/big5enc.c create mode 100644 app/tools/halibut/charset/big5set.c create mode 100644 app/tools/halibut/charset/charset.h create mode 100644 app/tools/halibut/charset/cns11643.c create mode 100644 app/tools/halibut/charset/cp949.c create mode 100644 app/tools/halibut/charset/cstable.c create mode 100644 app/tools/halibut/charset/enum.c create mode 100644 app/tools/halibut/charset/euc.c create mode 100644 app/tools/halibut/charset/fromucs.c create mode 100644 app/tools/halibut/charset/gb2312.c create mode 100644 app/tools/halibut/charset/hz.c create mode 100644 app/tools/halibut/charset/internal.h create mode 100644 app/tools/halibut/charset/iso2022.c create mode 100644 app/tools/halibut/charset/iso2022s.c create mode 100644 app/tools/halibut/charset/istate.c create mode 100644 app/tools/halibut/charset/jisx0208.c create mode 100644 app/tools/halibut/charset/jisx0212.c create mode 100644 app/tools/halibut/charset/ksx1001.c create mode 100644 app/tools/halibut/charset/locale.c create mode 100644 app/tools/halibut/charset/localenc.c create mode 100644 app/tools/halibut/charset/macenc.c create mode 100644 app/tools/halibut/charset/mimeenc.c create mode 100644 app/tools/halibut/charset/sbcs.c create mode 100644 app/tools/halibut/charset/sbcsdat.c create mode 100644 app/tools/halibut/charset/sbcsdat.h create mode 100644 app/tools/halibut/charset/shiftjis.c create mode 100644 app/tools/halibut/charset/slookup.c create mode 100644 app/tools/halibut/charset/superset.c create mode 100644 app/tools/halibut/charset/test.c create mode 100644 app/tools/halibut/charset/toucs.c create mode 100644 app/tools/halibut/charset/utf16.c create mode 100644 app/tools/halibut/charset/utf7.c create mode 100644 app/tools/halibut/charset/utf8.c create mode 100644 app/tools/halibut/charset/xenc.c create mode 100644 app/tools/halibut/contents.c create mode 100644 app/tools/halibut/deflate.c create mode 100644 app/tools/halibut/deflate.h create mode 100644 app/tools/halibut/error.c create mode 100644 app/tools/halibut/halibut.h create mode 100644 app/tools/halibut/help.c create mode 100644 app/tools/halibut/in_afm.c create mode 100644 app/tools/halibut/in_pf.c create mode 100644 app/tools/halibut/index.c create mode 100644 app/tools/halibut/input.c create mode 100644 app/tools/halibut/keywords.c create mode 100644 app/tools/halibut/licence.c create mode 100644 app/tools/halibut/main.c create mode 100644 app/tools/halibut/malloc.c create mode 100644 app/tools/halibut/misc.c create mode 100644 app/tools/halibut/paper.h create mode 100644 app/tools/halibut/psdata.c create mode 100644 app/tools/halibut/tree234.c create mode 100644 app/tools/halibut/tree234.h create mode 100644 app/tools/halibut/ustring.c create mode 100644 app/tools/halibut/version create mode 100644 app/tools/halibut/version.c create mode 100644 app/tools/halibut/wcwidth.c create mode 100644 app/tools/listxtp.c create mode 100644 app/tools/oldscripts/README create mode 100644 app/tools/oldscripts/checkall create mode 100644 app/tools/oldscripts/diffall create mode 100644 app/tools/oldscripts/fetchall create mode 100644 app/tools/oldscripts/makeall create mode 100644 app/tools/oldscripts/markall create mode 100644 app/tools/oldscripts/mkwinrlse create mode 100644 app/tools/oldscripts/roall (limited to 'app/tools') diff --git a/app/tools/CMakeLists.txt b/app/tools/CMakeLists.txt new file mode 100644 index 0000000..e6716f0 --- /dev/null +++ b/app/tools/CMakeLists.txt @@ -0,0 +1,18 @@ +ADD_EXECUTABLE(addcrlf addcrlf.c) + +ADD_EXECUTABLE(bin2c bin2c.c) + +SET ( SOURCES listxtp.c ) + +IF (WIN32) + SET ( SOURCES + ${SOURCES} + dirent.c) + + INCLUDE_DIRECTORIES( BEFORE ${CMAKE_CURRENT_SOURCE_DIR}) +ENDIF (WIN32) + +ADD_EXECUTABLE( listxtp ${SOURCES}) + +ADD_SUBDIRECTORY(halibut) + diff --git a/app/tools/HACKING b/app/tools/HACKING new file mode 100644 index 0000000..779bf58 --- /dev/null +++ b/app/tools/HACKING @@ -0,0 +1,35 @@ +/** \file filename.c + * This file shows the conventions used for inline documentation. + * + * $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/tools/HACKING,v 1.3 2007-11-13 19:31:12 m_fischer Exp $ + */ + +/* XTrkCad - Model Railroad CAD + * Copyright (C) + * + * 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 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 to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +int global; /**< this is a global variable */ + +/** + * Brief description of function. And some more words about + * this function bla bla bla + * + * \param varname1 IN this is a variable + * \param varname2 OUT and another one that is modified + * \return describe the return value + */ + diff --git a/app/tools/addcrlf.c b/app/tools/addcrlf.c new file mode 100644 index 0000000..d36310e --- /dev/null +++ b/app/tools/addcrlf.c @@ -0,0 +1,242 @@ +/** + * \file addcrlf.c Convert text between DOS, UNIX and MAC + * + * $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/tools/addcrlf.c,v 1.7 2007-02-13 19:46:25 m_fischer Exp $ + * + * This is heavily based on flip by Craig Stuart Sapp + * Web Address: http://www-ccrma.stanford.edu/~craig/utility/flip/flip.cpp + */ + +/* XTrkCad - Model Railroad CAD + * Copyright (C) Marin Fischer 2006 + * + * 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 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 to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include + +void exitUsage( char *cmd ); +void translateToDos( char *infile, char *outfile ); +void translateToUnix(char* infilename, char *outfilename); +void determineType(char* filename); + +int +main( int argc, char ** argv) +{ + char option; + + if( argc < 2 ) + exitUsage(argv[0]); + + if( argv[1][0] != '-' &&argv[1][0] != '/' ) + exitUsage(argv[0]); + + option = argv[1][1]; + + if (!(option == 'u' || option == 'd' || option == 't' || option =='h' )) { + exitUsage(argv[0]); + } + + if( !((option == 't' && argc == 3)||(option !='t' && argc==4)||( option =='h' ))) { + exitUsage(argv[0]); + } + switch( option ) + { + case 'd': + translateToDos(argv[2], argv[3]); + break; + case 'u': + translateToUnix(argv[2], argv[3]); + break; + case 'm': +/* translateToMacintosh(argv[i+2]); */ + break; + case 'h': + exitUsage(argv[0]); + break; + default: + determineType(argv[2]); + break; + } + return 0; +} + + + +void +translateToDos(char* infilename, char *outfilename) +{ + FILE *in, *out; + char ch, lastch; + int peekch; + + in = fopen( infilename, "rb" ); + if (!in) { + printf( "Error: cannot find file: %s\n", infilename ); + return; + } + + out = fopen( outfilename, "wb" ); + if (!out) { + printf( "Error: cannot open file: %s\n", outfilename ); + return; + } + + ch = getc( in ); + lastch = ch; + + while( !feof( in )) + { + if (ch == 0x0a && lastch != 0x0d) { + // convert newline from Unix to MS-DOS + putc( (char)0x0d, out ); + putc( ch, out ); + lastch = ch; + } else { + if (ch == 0x0d) { // convert newline from Mac to MS-DOS + peekch = getc( in ); // lookahead for following character + ungetc( peekch, in ); + + if (peekch != 0x0a) { + putc( ch, out ); + putc( (char)0x0a, out ); + lastch = 0x0a; + } else { + lastch = 0x0d; + // Bug fix here reported by Shelley Adams: running -d + // twice in a row was generating Unix style newlines + // without the following statement: + putc( 0x0d, out ); + } + + } else { + putc( ch, out ); + lastch = ch; + } + } + ch = getc( in ); + } + + fclose( in ); + fclose( out ); +} + +void +translateToUnix(char* infilename, char *outfilename) +{ + FILE *in, *out; + char ch, lastch; + + in = fopen( infilename, "rb" ); + if (!in) { + printf( "Error: cannot find file: %s\n", infilename ); + return; + } + + out = fopen( outfilename, "wb" ); + if (!out) { + printf( "Error: cannot open file: %s\n", outfilename ); + return; + } + + ch = getc( in ); + lastch = ch; + + while( !feof( in )) + { + if (ch == 0x0d) { + putc( (char)0x0a, out ); + } else { + if (ch == 0x0a) { + if (lastch == 0x0d) { + // do nothing: already converted MSDOS newline to Unix form + } else { + putc( (char)0x0a, out ); + } + } else { + putc( ch, out ); + } + } + lastch = ch; + ch = getc( in ); + } + + fclose( in ); + fclose( out ); +} + +void +determineType(char* filename) +{ + FILE *in; + int ch; + int crcount = 0; + int lfcount = 0; + + in = fopen( filename, "rb" ); + if (!in) { + printf( "Error: cannot find file: %s\n", filename ); + return; + } + + ch = getc( in ); + if( ch == EOF ) { + printf( "Error: file could not be read: %s\n", filename ); + return; + } + + while( !feof( in )) + { + if (ch == 0x0d) { + crcount ++; + } else { + if (ch == 0x0a) { + lfcount++; + } + } + ch = getc( in ); + } + + fclose( in ); + + if ((lfcount == crcount) && (crcount != 0)) { + printf("%s : DOS\n", filename ); + } else if ((lfcount > 0) && (crcount == 0)) { + printf("%s : UNIX\n", filename ); + } else if ((lfcount == 0) && (crcount > 0)) { + printf("%s : MAC\n", filename ); + } else if ((lfcount > 0) && (crcount > 0)) { + printf("%s : MIXED\n", filename ); + } else { + printf("%s : UNKNOWN\n", filename ); + } +} + +void +exitUsage( char* commandName ) +{ + printf( "\nUsage: %s [-h] | [-t infile] | [[-u|-d|-m] infile outfile]\n" + " Converts an ASCII file between Unix, MS-DOS/Windows, or Macintosh newline formats\n\n" + " Options: \n" + " -u = convert file to Unix newline format (newline)\n" + " -d = convert file to MS-DOS/Windows newline format (linefeed + newline)\n" + " -m = convert file to Macintosh newline format (linefeed)\n" + " -t = display current file type, no file modifications\n" + " -h = show this help\n", + commandName ); + + exit(1); +} diff --git a/app/tools/bin2c.c b/app/tools/bin2c.c new file mode 100644 index 0000000..bb619dc --- /dev/null +++ b/app/tools/bin2c.c @@ -0,0 +1,126 @@ +/* +BIN2C V1.0 CODED BY CHRISTIAN PADOVANO ON 17-MAY-1995 +this little utility translates a binary file in a useful C structure +that can be included in a C source. +to contact me write to EMAIL: [[Email Removed]] +*/ + + +#include +#include +#include +#include + +#define BUF_LEN 1024 +#define LINE 12 + +/* Tell u the file size in bytes */ + +long int filesize( FILE *fp ) +{ + long int save_pos, size_of_file; + + save_pos = ftell( fp ); + fseek( fp,0L, SEEK_END ); + size_of_file = ftell( fp ); + fseek( fp, save_pos, SEEK_SET ); + return( size_of_file ); +} + + +/* lower chars --> upper chars */ + +void Upper_chars(char *buffer) +{ + unsigned int c; + + for (c=0; c <= strlen(buffer)-1; c++) + *(buffer+c)=toupper( *( buffer+c) ); +} + + +int main( int argc, char **argv ) +{ + FILE *source,*dest; + char Dummy[BUF_LEN]; + int buffer; + int c; + + if ( (argc < 4) ) + { + + if ( ( argc == 2 ) && ( strcmp(argv[1],"-h")==0 ) ) + { + puts(" - <<< BIN2C V1.0 >>> by Christian Padovano - \n"); + puts("USAGE: bin2C "); + puts("\n = name of the C structure in the destination file name.\n"); + puts(" = without extension '.h' it will be added by program."); + return EXIT_SUCCESS; + } + else + { + puts("Bad arguments !!! You must give me all the parameters !!!!\n" + "Type 'bin2c -h' to read the help !!!! "); + return EXIT_SUCCESS; + } + + } + + if( (source=fopen( argv[1], "rb" )) == NULL ) + { + printf("ERROR : I can't find source file %s\n",argv[1]); + return EXIT_FAILURE; + } + + strcpy(Dummy,argv[2]); + strcat(Dummy,".h"); /* add suffix .h to target name */ + + if( (dest=fopen( Dummy, "wb+" )) == NULL ) + { + printf("ERROR : I can't open destination file %s\n",Dummy); + return EXIT_FAILURE; + } + + + strcpy(Dummy,argv[3]); + Upper_chars(Dummy); /* lower to upper chars */ + strcat(Dummy,"_LEN"); /* add the suffix _LEN to the struct name */ + /* for the #define stantment */ + + + /* It writes the header information */ + fprintf( dest, "\n#define %s %ld\n\n", Dummy, filesize(source) ); + fprintf( dest, "static unsigned char %s[] = {\n ", argv[3] ); + + if( ferror( dest )) + { + printf( "ERROR writing on target file: %s\n",argv[2] ); + return EXIT_FAILURE; + } + + + c = 0; + buffer = fgetc( source ); + + while( buffer != EOF ) + { + fprintf(dest,"0x%02x", buffer); + + buffer = fgetc( source ); + if( !feof(source)) + fputc(',', dest); + + c++; + if(c == LINE ) { + fprintf(dest,"\n "); + c = 0; + } + + } + + fprintf(dest,"\n};\n\n"); + + return EXIT_SUCCESS; +} + + diff --git a/app/tools/dirent.c b/app/tools/dirent.c new file mode 100644 index 0000000..08ea800 --- /dev/null +++ b/app/tools/dirent.c @@ -0,0 +1,145 @@ +/* + + Implementation of POSIX directory browsing functions and types for Win32. + + Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com) + History: Created March 1997. Updated June 2003. + Rights: See end of file. + +*/ + +#include +#include +#include /* _findfirst and _findnext set errno iff they return -1 */ +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct DIR +{ + long handle; /* -1 for failed rewind */ + struct _finddata_t info; + struct dirent result; /* d_name null iff first time */ + char *name; /* null-terminated char string */ +}; + +DIR *opendir(const char *name) +{ + DIR *dir = 0; + + if(name && name[0]) + { + size_t base_length = strlen(name); + const char *all = /* search pattern must end with suitable wildcard */ + strchr("/\\", name[base_length - 1]) ? "*" : "/*"; + + if((dir = (DIR *) malloc(sizeof *dir)) != 0 && + (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0) + { + strcat(strcpy(dir->name, name), all); + + if((dir->handle = (long) _findfirst(dir->name, &dir->info)) != -1) + { + dir->result.d_name = 0; + } + else /* rollback */ + { + free(dir->name); + free(dir); + dir = 0; + } + } + else /* rollback */ + { + free(dir); + dir = 0; + errno = ENOMEM; + } + } + else + { + errno = EINVAL; + } + + return dir; +} + +int closedir(DIR *dir) +{ + int result = -1; + + if(dir) + { + if(dir->handle != -1) + { + result = _findclose(dir->handle); + } + + free(dir->name); + free(dir); + } + + if(result == -1) /* map all errors to EBADF */ + { + errno = EBADF; + } + + return result; +} + +struct dirent *readdir(DIR *dir) +{ + struct dirent *result = 0; + + if(dir && dir->handle != -1) + { + if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) + { + result = &dir->result; + result->d_name = dir->info.name; + } + } + else + { + errno = EBADF; + } + + return result; +} + +void rewinddir(DIR *dir) +{ + if(dir && dir->handle != -1) + { + _findclose(dir->handle); + dir->handle = (long) _findfirst(dir->name, &dir->info); + dir->result.d_name = 0; + } + else + { + errno = EBADF; + } +} + +#ifdef __cplusplus +} +#endif + +/* + + Copyright Kevlin Henney, 1997, 2003. All rights reserved. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose is hereby granted without fee, provided + that this copyright and permissions notice appear in all copies and + derivatives. + + This software is supplied "as is" without express or implied warranty. + + But that said, if there are any problems please get in touch. + +*/ diff --git a/app/tools/dirent.h b/app/tools/dirent.h new file mode 100644 index 0000000..a02a0d8 --- /dev/null +++ b/app/tools/dirent.h @@ -0,0 +1,50 @@ +#ifndef DIRENT_INCLUDED +#define DIRENT_INCLUDED + +/* + + Declaration of POSIX directory browsing functions and types for Win32. + + Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com) + History: Created March 1997. Updated June 2003. + Rights: See end of file. + +*/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct DIR DIR; + +struct dirent +{ + char *d_name; +}; + +DIR *opendir(const char *); +int closedir(DIR *); +struct dirent *readdir(DIR *); +void rewinddir(DIR *); + +/* + + Copyright Kevlin Henney, 1997, 2003. All rights reserved. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose is hereby granted without fee, provided + that this copyright and permissions notice appear in all copies and + derivatives. + + This software is supplied "as is" without express or implied warranty. + + But that said, if there are any problems please get in touch. + +*/ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/tools/halibut/CMakeLists.txt b/app/tools/halibut/CMakeLists.txt new file mode 100644 index 0000000..ec7d74b --- /dev/null +++ b/app/tools/halibut/CMakeLists.txt @@ -0,0 +1,32 @@ +SET(SOURCES + biblio.c + bk_html.c + contents.c + deflate.c + error.c + halibut.h + help.c + index.c + input.c + in_pf.c + in_afm.c + psdata.c + bk_paper.c + keywords.c + licence.c + main.c + malloc.c + misc.c + tree234.c + tree234.h + ustring.c + version.c + wcwidth.c + ) + +INCLUDE_DIRECTORIES(charset) +ADD_EXECUTABLE(halibut ${SOURCES}) +TARGET_LINK_LIBRARIES(halibut xtrkcad-charset) + +ADD_SUBDIRECTORY(charset) + diff --git a/app/tools/halibut/LICENCE b/app/tools/halibut/LICENCE new file mode 100644 index 0000000..972c0df --- /dev/null +++ b/app/tools/halibut/LICENCE @@ -0,0 +1,36 @@ +Halibut is copyright (c) 1999-2007 Simon Tatham. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, +and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Halibut contains font metrics derived from the "Font Metrics for PDF +Core 14 Fonts", which carry the following copyright notice and licence: + + Copyright (c) 1985, 1987, 1989, 1990, 1991, 1992, 1993, 1997 + Adobe Systems Incorporated. All Rights Reserved. + + This file and the 14 PostScript(R) AFM files it accompanies may be + used, copied, and distributed for any purpose and without charge, + with or without modification, provided that all copyright notices + are retained; that the AFM files are not distributed without this + file; that all modifications to this file or any of the AFM files + are prominently noted in the modified file(s); and that this + paragraph is not modified. Adobe Systems has no responsibility or + obligation to support the use of the AFM files. diff --git a/app/tools/halibut/README b/app/tools/halibut/README new file mode 100644 index 0000000..b602834 --- /dev/null +++ b/app/tools/halibut/README @@ -0,0 +1,36 @@ +HALIBUT Readme +============== + +This version of Halibut has been adapted to the needs of the XTrkCad +Project. It is based on version 1 of Halibut. + +The original version is available at: + +http://www.chiark.greenend.org.uk/~sgtatham/halibut/ + +This site also has the full documentation. + +XTrkCad Modifications +--------------------- + +The following changes have been made: + +1. Backends - only the HTML backend is included + +2. \f: Emphasize more + This formating instruction is similar to the \e. It is usually rendered + as bold on HTML + + Example: Here is some \f{bold text}. + + Nesting of \e and \f is unsupported. + +3 \G: Include graphic + This instruction is used to include bitmaps into the document. Note that + there are no checks for presence of the file nor whether its a valid + graphics format. + + \G just takes the filename as a parameter. + + Example: Include a bitmap here \G{png.d/bitmap.png}. + diff --git a/app/tools/halibut/biblio.c b/app/tools/halibut/biblio.c new file mode 100644 index 0000000..7ce163d --- /dev/null +++ b/app/tools/halibut/biblio.c @@ -0,0 +1,105 @@ +/* + * biblio.c: process the bibliography + */ + +#include +#include "halibut.h" + +static wchar_t *gentext(int num) { + wchar_t text[22]; + wchar_t *p = text + lenof(text); + *--p = L'\0'; + *--p = L']'; + while (num != 0) { + assert(p > text); + *--p = L"0123456789"[num % 10]; + num /= 10; + } + assert(p > text); + *--p = L'['; + return ustrdup(p); +} + +static void cite_biblio(keywordlist *kl, wchar_t *key, filepos fpos) { + keyword *kw = kw_lookup(kl, key); + if (!kw) + error(err_nosuchkw, &fpos, key); + else { + /* + * We've found a \k reference. If it's a + * bibliography entry ... + */ + if (kw->para->type == para_Biblio) { + /* + * ... then mark the paragraph as cited. + */ + kw->para->type = para_BiblioCited; + } + } +} + +/* + * Make a pass through the source form, generating citation formats + * for bibliography entries and also marking which bibliography + * entries are actually cited (or \nocite-ed). + */ + +void gen_citations(paragraph *source, keywordlist *kl) { + paragraph *para; + int bibnum = 0; + + for (para = source; para; para = para->next) { + word *ptr; + + /* + * \BR and \nocite paragraphs get special processing here. + */ + if (para->type == para_BR) { + keyword *kw = kw_lookup(kl, para->keyword); + if (!kw) { + error(err_nosuchkw, ¶->fpos, para->keyword); + } else if (kw->text) { + error(err_multiBR, ¶->fpos, para->keyword); + } else { + kw->text = dup_word_list(para->words); + } + } else if (para->type == para_NoCite) { + wchar_t *wp = para->keyword; + while (*wp) { + cite_biblio(kl, wp, para->fpos); + wp = uadv(wp); + } + } + + /* + * Scan for keyword references. + */ + for (ptr = para->words; ptr; ptr = ptr->next) { + if (ptr->type == word_UpperXref || + ptr->type == word_LowerXref) + cite_biblio(kl, ptr->text, ptr->fpos); + } + } + + /* + * We're now almost done; all that remains is to scan through + * the cited bibliography entries and invent default citation + * texts for the ones that don't already have explicitly + * provided \BR text. + */ + for (para = source; para; para = para->next) { + if (para->type == para_BiblioCited) { + keyword *kw = kw_lookup(kl, para->keyword); + assert(kw != NULL); + if (!kw->text) { + word *wd = smalloc(sizeof(word)); + wd->text = gentext(++bibnum); + wd->type = word_Normal; + wd->alt = NULL; + wd->next = NULL; + kw->text = wd; + } + para->kwtext = kw->text; + } + } +} diff --git a/app/tools/halibut/bk_html.c b/app/tools/halibut/bk_html.c new file mode 100644 index 0000000..8b5443b --- /dev/null +++ b/app/tools/halibut/bk_html.c @@ -0,0 +1,2791 @@ +/* + * HTML backend for Halibut + */ + +/* + * TODO: + * + * - I'm never entirely convinced that having a fragment link to + * come in at the start of the real text in the file is + * sensible. Perhaps for the topmost section in the file, no + * fragment should be used? (Though it should probably still be + * _there_ even if unused.) + * + * - In HHK index mode: subsidiary hhk entries (as in replacing + * `foo, bar' with `foo\n\tbar') can be done by embedding + * sub-