Navigate

· Home page

· Bio

· Projects

· Tips & Tricks

    · LaTeX

        · BibTeX

    · C/C++

    · DOCTYPEs

    · Linux

· Programming

· More Links

· Colleagues

· Weekly Schedule

· Research


Trent Apted's Photo




Trent Apted's Tips & Tricks

Last updated 2005-07-06 (partially)

LaTeX

LaTeX fonts

BibTeX to Endnote Converter

LaTeX Preamble

\usepackage{times}
\usepackage{fancyhdr}
\usepackage{epsfig}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{theorem}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{epic}
\usepackage{setspace}
\usepackage{psfrag}
\usepackage{url}
\usepackage{flushend}
\usepackage[T1]{fontenc}
\usepackage{ae,aecompl}
\usepackage[british]{babel}
\usepackage{hyphenat}
\usepackage[ps2pdf, backref, bookmarks, bookmarksopen=true, bookmarksnumbered=true]{hyperref}
\@ifundefined{newblock}{\def\newblock{\par}}{}
\widowpenalty=2000
\clubpenalty=2000
\hyphenpenalty=1000
\tolerance=1000

C/C++

Determining what preprocessor macros are predefined

I keep forgetting how to do this, so I'm dumping it here to remind me. Basically, if you want to see what macros are predefined (e.g. so you know whether you can go #ifdef __win32__) then you can do the following:

touch foo.h; cpp -ansi -dM foo.h

The -ansi is optional, but I recommend it. Source.

Disabling canonical input

Most C/C++ console applications will not receive any input from stdin until the Enter key is pressed. This is actually conrolled by the terminal itself and can be changed with

$ stty -icanon min 1

from the command line or in code as follows:

#include <termios.h>
#include <unistd.h>

static struct termios stored_settings;

void set_keypress(void) {
    struct termios new_settings;
    tcgetattr(0, &stored_settings);
    new_settings = stored_settings;
    new_settings.c_lflag &= ~ICANON;
    /*new_settings.c_lflag &= ~ECHO;*/ /*turn off local echo*/
    new_settings.c_cc[VTIME] = 0;
    tcgetattr(0, &stored_settings);
    new_settings.c_cc[VMIN] = 1;
    tcsetattr(0, TCSANOW, &new_settings);
}

void reset_keypress(void) {
    tcsetattr(0, TCSANOW, &stored_settings);
}

In other words, this is how you receive keyboard input from a terminal or console immediately, without having to press the enter key.

You might use this to read the size of someone's terminal, say, in an ANSI-compliant manner (and without using curses, slang, nor relying on the shell to set the LINES and COLUMNS environment variables correctly):

#include <stdio.h>

int main() {
    int oldrow, oldcol, rows, cols;
    set_keypress(); 
    fprintf(stdout, "\033[6n");
    fscanf(stdin, "\033[%d;%dR", &oldrow, &oldcol);
    fprintf(stdout, "\033[10000;10000f\033[6n");
    fscanf(stdin, "\033[%d;%dR", &rows, &cols);
    fprintf(stdout, "\033[%d;%dfYour Terminal is %d rows x %d cols\n", oldrow, oldcol, rows, cols);
    reset_keypress();
    return 0;
}

Note that for this to work 'nicely' the ECHO line in set_keypress should be uncommented.
See also ANSI Escape sequences

DOCTYPES

"Almost Standards Mode"

HTML Transitional

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

HTML Frameset

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

XHTML Transitional

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

XHTML Frameset

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN">

"Full Standards Mode"

Full XHTML Strict (always try and start with this)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">

Also see XHTML 1.0 - DTDs
Character entity references in HTML 4

Linux

I gave a talk all about Linux Daemons (Servers) for a short course. Slides are available (2.6MB PDF) as well handouts (1.5MB). Made with LaTeX beamer -- feel free to check out the source code (no images).

There are also some files and notes about cross-compiling under Linux, to an arm platform running Linux Familiar.