A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

These warnings:

warning: initialization makes pointer from integer without a cast
warning: assignment makes pointer from integer without a cast

...for a line containing malloc could mean that you forgot to #include "stdlib.h".
Functions are assumed to return an integer type by default if not declared.

C printf and scanf format specifiers

Format Specifier

Type

%d (or %i)

int

%c

char

%f

float

%lf

double

%s

string

%xhexadecimal

Comparing strings in C

In c it is not possible to directly compare two strings so a statement like if (string1==string2) is not valid. Most c libraries contain a function called the strcmp().This is used to compare two strings in the following manner.

if(strcmp(name1,name2)==0)
 puts("The names are the same");
else
 puts("The names are not the same.");

Thanks johnt

debugging technique

When programming C, it can be difficult to track down a segmentation fault.
It is often caused by attempting to read uninitialised memory.

Try skipping parts of the program until you locate the statement causing it.

Then replace each part of the data by hard-coded values, one by one, until you find the uninitialised variable/pointer.

c logging

if your fprintf statements don't reach the apache error log, you may have to flush the output buffer:

fprintf(stderr, "error statement\n");
fflush(stderr);


Logging in an apache handler

ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "debug message");

C pointer error

This error:

    request for member `xxx' in something not a structure or union

...could mean you need to use structure->member instead of structure.member, as sturcture is a pointer.

Burning DVDs

2008: Windows

  • DVD Flick is perfect for combining .AVI video with .SRT subtitles to produce DVD files.
  • DVD Shrink can reduce a commercial DVD in size to fit onto a standard 4.7Gb blank DVD. There is no noticable loss of quality.
  • Leawo DVD to MP4 Converter works well.
  • Frontends using cdrtools are supposed to burn .VOB files, but I couldn't get this to work. Nothing beats Nero 6 if you can find an old copy. The latest version is 185Mb, and you have to pay for it!


Sep 2012:

  • Free trial of Aimersoft DVD Creator easily burns MP4 files to DVD. It's easy to create chapters. But it writes a watermark in the middle of the screen.


c function errors

Errors like these:

previous implicit declaration of `function'

`function' was previously implicitly declared to return `int'

...point to a missing function declaration at the top of the file.

Concatenate C strings, and return them from a function

Don't do this. Just use strcat() and strncpy() instead.

#include <stdlib.h>

char* concat(char*, char*);

int main (int argc, char** argv)
{
char *x = "something";
char *y = " completely different.";
  char *combined = concat(x, y);
printf("And now for %s\n", combined);
}

char* concat(char *a, char *b)
{
  char *target = malloc( strlen(a) + strlen(b) + 1 );
  strcpy(target,a);
strcat(target,b);
return target;
}

C static

The keyword 'static' before a function name means that the function will only be available to callers in the file where it is declared.

Regular expressions in C

Using glibc's regex.h
  • Make sure the number of expected matches (nmatch) is high enough, or there will be garbage at the end of the matchptr array
  • If regexec() succeeds [returns zero], matchptr contains:
    • 0: the whole regex
    • 1: first parenthesis match
  • if regexec() fails [returns a value], don't even look in matchptr
  • Characters that must be escaped:
    • parentheses
    • plus signs
  • If you're matching the end of line, it must be inside any parenthesis!

location of C libs on nolsearch09

according to gcc -print-search-dirs

/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../bcc/include

or

/usr/lib/bcc/include

Deeply copy a perl hash

use Storable;

$bad_recipe = dclone($recipe);

Vim: Turn tabs into spaces

:set tabstop=4

:set expandtab

MySQL variables - caching

http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html

Show cache status
> show variables like 'query%';
Show cache counters
mysql> show status like 'qc%';

Bash regular expressions

Log4perl log levels

OFF
FATAL
ERROR
WARN
INFO
DEBUG
TRACE
ALL

vi tab length

:set tabstop=4

Delete documents from IDOL

http://host:indexport/DREDELETEDOC?docs=[doc IDs]&DREDBname=[DB name]

[DB name] is mandatory

See also DREDELETEREF