ctm.h revision 3833
1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@login.dknet.dk> wrote this file.  As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
9 * $Id: ctm.h,v 1.4 1994/09/22 02:49:16 phk Exp $
10 *
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
16#include <md5.h>
17#include <ctype.h>
18#include <string.h>
19#include <errno.h>
20#include <sys/types.h>
21#include <sys/stat.h>
22#include <sys/file.h>
23
24#define VERSION "2.0"
25#define MAXSIZE (1024*1024*10)
26
27/* The fields... */
28#define CTM_F_MASK		0xff
29#define CTM_F_Name		0x01
30#define CTM_F_Uid		0x02
31#define CTM_F_Gid		0x03
32#define CTM_F_Mode		0x04
33#define CTM_F_MD5		0x05
34#define CTM_F_Count		0x06
35#define CTM_F_Bytes		0x07
36
37/* The qualifiers... */
38#define CTM_Q_MASK		0xff00
39#define CTM_Q_Name_File		0x0100
40#define CTM_Q_Name_Dir		0x0200
41#define CTM_Q_Name_New		0x0400
42#define CTM_Q_MD5_After		0x0100
43#define CTM_Q_MD5_Before	0x0200
44#define CTM_Q_MD5_Chunk		0x0400
45#define CTM_Q_MD5_Force		0x0800
46
47struct CTM_Syntax {
48    char	*Key;
49    int		*List;
50    };
51
52extern struct CTM_Syntax Syntax[];
53
54#define Malloc malloc
55#define Free free
56
57#ifndef EXTERN
58#  define EXTERN extern
59#endif
60EXTERN u_char *Version;
61EXTERN u_char *Name;
62EXTERN u_char *Nbr;
63EXTERN u_char *TimeStamp;
64EXTERN u_char *Prefix;
65EXTERN u_char *FileName;
66EXTERN u_char *BaseDir;
67EXTERN u_char *TmpDir;
68
69/*
70 * Paranoid -- Just in case they should be after us...
71 *  0 not at all.
72 *  1 normal.
73 *  2 somewhat.
74 *  3 you bet!.
75 *
76 * Verbose -- What to tell mom...
77 *  0 Nothing which wouldn't surprise.
78 *  1 Normal.
79 *  2 Show progress '.'.
80 *  3 Show progress names, and actions.
81 *  4 even more...
82 *  and so on
83 *
84 * ExitCode -- our Epitaph
85 *  0 Perfect, all input digested, no problems
86 *  1 Bad input, no point in retrying.
87 *  2 Pilot error, commandline problem &c
88 *  4 Out of resources.
89 *  8 Destination-tree not correct.
90 * 16 Destination-tree not correct, can force.
91 * 32 Internal problems.
92 *
93 */
94
95EXTERN int Paranoid;
96EXTERN int Verbose;
97EXTERN int Exit;
98EXTERN int Force;
99EXTERN int CheckIt;
100
101#define Exit_OK		0
102#define Exit_Garbage	1
103#define Exit_Pilot	2
104#define Exit_Broke	4
105#define Exit_NotOK	8
106#define Exit_Forcible	16
107#define Exit_Mess	32
108#define Exit_Done	64
109
110char * String(char *s);
111void Fatal_(int ln, char *fn, char *kind);
112#define Fatal(foo) Fatal_(__LINE__,__FILE__,foo)
113#define Assert() Fatal_(__LINE__,__FILE__,"Assert failed.")
114#define WRONG {Assert(); return Exit_Mess;}
115
116u_char * Ffield(FILE *fd, MD5_CTX *ctx,u_char term);
117
118int Fbytecnt(FILE *fd, MD5_CTX *ctx, u_char term);
119
120u_char * Fdata(FILE *fd, int u_chars, MD5_CTX *ctx);
121
122#define GETFIELD(p,q) if(!((p)=Ffield(fd,&ctx,(q)))) return BADREAD
123#define GETFIELDCOPY(p,q) if(!((p)=Ffield(fd,&ctx,(q)))) return BADREAD; else p=String(p)
124#define GETBYTECNT(p,q) if(0 >((p)= Fbytecnt(fd,&ctx,(q)))) return BADREAD
125#define GETDATA(p,q) if(!((p) = Fdata(fd,(q),&ctx))) return BADREAD
126
127int Pass1(FILE *fd);
128int Pass2(FILE *fd);
129int Pass3(FILE *fd);
130
131int ctm_edit(u_char *script, int length, char *filein, char *fileout);
132