netatalk: printcap.c File Reference

netatalk 4.5.1
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
printcap.c File Reference

routines for dealing with the terminal capability data base based on termcap More...

`#include <ctype.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include <stdlib.h>`
`#include <unistd.h>`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include <fcntl.h>`
`#include <atalk/logger.h>`
`#include <atalk/compat.h>`
`#include "printcap.h"`

## Macros
#define | BUFSIZ 1024
#define | MAXHOP 32
#define | PRINTCAP
#define | tgetent pgetent
#define | tskip pskip
#define | tgetstr pgetstr
#define | tdecode pdecode
#define | tgetnum pgetnum
#define | tgetflag pgetflag
#define | tdecode pdecode
#define | tnchktc pnchktc
#define | tnamatch pnamatch
#define | V6

## Functions
int | getprent (char *cap, char *bp, int bufsize)
| Similar to tgetent except it returns the next entry instead of doing a lookup.
void | endprent (void)
int | tgetent (char *cap, char *bp, const char *name)
| Get an entry for terminal name in buffer bp, from the termcap file.
int | tnchktc (char *cap)
| check the last entry, see if it's tc=xxx.
int | tnamatch (const char *np)
| deals with name matching.
static char * | tskip (char *bp)
| Skip to the next field. Notice that this is very dumb, not knowing about \: escapes or any such. If necessary, :'s can be put into the termcap file in octal.
int | tgetnum (char *id)
| Return the (numeric) option id.
int | tgetflag (char *id)
| Handle a flag option.
static char * | tdecode (char *str, char **area)
char * | tgetstr (char *id, char **area)
| Get a string valued option.
static char * | decodename (char *str, char **area, int bufsize)
char * | getpname (char **area, int bufsize)

## Variables
static FILE * | pfp = NULL
static char * | tbuf
static int | hopcount

## Detailed Description

routines for dealing with the terminal capability data base based on termcap

Bug
  Should use a "last" pointer in tbuf, so that searching for capabilities alphabetically would not be a n**2/2 process when large numbers of capabilities are given.

Note
  If we add a last pointer now we will screw up the tc capability. We really should compile termcap.

Essentially all the work here is scanning and decoding escapes in string capabilities. We don't use stdio because the editor doesn't, and because living w/o it is not hard.

## Macro Definition Documentation

## ◆ BUFSIZ

#define BUFSIZ 1024

## ◆ MAXHOP

#define MAXHOP 32

max number of tc= indirections

## ◆ PRINTCAP

#define PRINTCAP

## ◆ tdecode [1/2]

#define tdecode pdecode

## ◆ tdecode [2/2]

#define tdecode pdecode

## ◆ tgetent

#define tgetent pgetent

## ◆ tgetflag

#define tgetflag pgetflag

## ◆ tgetnum

#define tgetnum pgetnum

## ◆ tgetstr

#define tgetstr pgetstr

## ◆ tnamatch

#define tnamatch pnamatch

## ◆ tnchktc

#define tnchktc pnchktc

## ◆ tskip

#define tskip pskip

## ◆ V6

#define V6

## Function Documentation

## ◆ decodename()

char * decodename | ( | char * | str,
|  | char ** | area,
|  | int | bufsize )
| static

## ◆ endprent()

void endprent | ( | void |  | ) |

## ◆ getpname()

char * getpname | ( | char ** | area,
|  | int | bufsize )

## ◆ getprent()

int getprent | ( | char * | cap,
|  | char * | bp,
|  | int | bufsize )

Similar to tgetent except it returns the next entry instead of doing a lookup.

Note
  Added a "cap" parameter, so we can use these calls for printcap and papd.conf.

## ◆ tdecode()

char * tdecode | ( | char * | str,
|  | char ** | area )
| static

Tdecode does the grunt work to decode the string capability escapes.

## ◆ tgetent()

int tgetent | ( | char * | cap,
|  | char * | bp,
|  | const char * | name )

Get an entry for terminal name in buffer bp, from the termcap file.

Note
  Parse is very rudimentary; we just notice escaped newlines.

Added a "cap" parameter, so we can use these calls for printcap and papd.conf.

## ◆ tgetflag()

int tgetflag | ( | char * | id | ) |

Handle a flag option.

Flag options are given "naked", i.e. followed by a : or the end of the buffer.

Returns
  1 if we find the option, or 0 if it is not given.

## ◆ tgetnum()

int tgetnum | ( | char * | id | ) |

Return the (numeric) option id.

Numeric options look like

li#80

i.e. the option string is separated from the numeric value by a # character. If the option is not found we return -1. Note that we handle octal numbers beginning with 0.

## ◆ tgetstr()

char * tgetstr | ( | char * | id,
|  | char ** | area )

Get a string valued option.

These are given as

cl=^Z

Much decoding is done on the strings, and the strings are placed in area, which is a ref parameter which is updated. No checking on area overflow.

## ◆ tnamatch()

int tnamatch | ( | const char * | np | ) |

deals with name matching.

The first field of the termcap entry is a sequence of names separated by |'s, so we compare against each such name. The normal : terminator after the last name (before the first field) stops us.

## ◆ tnchktc()

int tnchktc | ( | char * | cap | ) |

check the last entry, see if it's tc=xxx.

If so, recursively find xxx and append that entry (minus the names) to take the place of the tc=xxx entry. This allows termcap entries to say "like an HP2621 but doesn't turn on the labels". Note that this works because of the left to right scan.

Added a "cap" parameter, so we can use these calls for printcap and papd.conf.

## ◆ tskip()

char * tskip | ( | char * | bp | ) |
| static

Skip to the next field. Notice that this is very dumb, not knowing about \: escapes or any such. If necessary, :'s can be put into the termcap file in octal.

## Variable Documentation

## ◆ hopcount

int hopcount
| static

detect infinite loops in termcap, init 0

## ◆ pfp

FILE* pfp = NULL
| static

printcap data base file pointer

## ◆ tbuf

char* tbuf
| static