File: malaga_files.c

package info (click to toggle)
malaga 7.12-7
  • links: PTS
  • area: main
  • in suites: bullseye, sid
  • size: 3,040 kB
  • ctags: 2,283
  • sloc: ansic: 21,457; sh: 8,168; lisp: 504; makefile: 270
file content (108 lines) | stat: -rw-r--r-- 3,440 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Copyright (C) 1995 Bjoern Beutel. */

/* Description. =============================================================*/

/* This module defines the structure of compiled Malaga files. */

/* Includes. ================================================================*/

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <setjmp.h>
#include <glib.h>
#include "basic.h"
#include "files.h"
#include "malaga_files.h"

/* Constants. ===============================================================*/

static char_t malaga[] = "MALAGA"; /* Magic key. */

/* Variables. ===============================================================*/

static time_t sym_stamp; /* Stamp for the ".sym" file or 0. */
static time_t esym_stamp; /* Stamp for the ".esym" file or 0. */

/* Functions. ===============================================================*/

void 
check_header( common_header_t *header, 
              string_t file_name, int_t file_type, 
	      int_t min_code_version, int_t max_code_version )
/* Check if HEADER is of FILE_TYPE and 
 * between MIN_CODE_VERSION and MAX_CODE_VERSION.
 * FILE_NAME is needed for error messages. */
{ 
  if (memcmp( header->malaga, malaga, sizeof( char_t ) * MALAGA_LEN ) != NULL) 
    complain( "\"%s\" is not a Malaga file.", file_name );
  if (header->file_type != file_type) 
    complain( "\"%s\" is wrong file type.", file_name );
  if (header->code_version < min_code_version) 
    complain( "\"%s\" is old code version. Maybe recompile?", file_name );
  if (header->code_version > max_code_version)
  {
    complain( "\"%s\" is new code version. Use newer Malaga version.", 
	      file_name);
  }
  if (file_type == SYMBOL_FILE) 
  { 
    sym_stamp = header->sym_stamp;
    esym_stamp = header->esym_stamp;
    split_hangul_syllables = header->split_hangul_syllables;
  } 
  else if (header->sym_stamp != sym_stamp) 
  { 
    complain( "\"%s\" uses %s \".sym\" file.", file_name,
	      header->sym_stamp < sym_stamp ? "older" : "newer" );
  } 
  else if (header->esym_stamp != 0) 
  { 
    if (esym_stamp == 0) 
      complain( "\"%s\" needs \".esym\" file.", file_name );
    else if (header->esym_stamp != esym_stamp) 
    {
      complain( "\"%s\" uses %s \".esym\" file.", file_name,
		header->esym_stamp < esym_stamp ? "older" : "newer" );
    }
  } 
  else if (header->split_hangul_syllables != split_hangul_syllables) 
  {
    complain( "\"%s\" %s split Hangul syllables.", file_name,
	      split_hangul_syllables ? "must" : "must not" );
  }
}

/*---------------------------------------------------------------------------*/

void 
set_sym_stamp( void )
/* Create a stamp for the ".sym" file. */
{ 
  time( &sym_stamp ); 
}

/*---------------------------------------------------------------------------*/

void 
set_esym_stamp( void )
/* Create a stamp for the ".esym" file. */
{ 
  time( &esym_stamp );
}

/*---------------------------------------------------------------------------*/

void 
set_header( common_header_t *header, int_t file_type, int_t code_version )
/* Set HEADER to be of FILE_TYPE and CODE_VERSION. */
{ 
  memcpy( header->malaga, malaga, sizeof( char_t ) * MALAGA_LEN );
  header->file_type = file_type;
  header->split_hangul_syllables = split_hangul_syllables;
  header->code_version = code_version;
  header->sym_stamp = sym_stamp;
  header->esym_stamp = esym_stamp;
}

/* End of file. =============================================================*/