atlas  0.6
Classes | Macros | Typedefs | Enumerations | Functions | Variables
ctangle.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include "common.h"
Include dependency graph for ctangle.c:

Classes

struct  text
 
struct  output_state
 

Macros

#define version_string   "x3.6"
 
#define banner   "This is CTANGLE (version "version_string")"
 
#define max_toks   150000L
 
#define max_texts   2500
 
#define max_files   50
 
#define stack_size_max   50
 
#define max_indent   1000
 
#define variant   text
 
#define line_output   flags['l']
 
#define max_bytes   50000L \
 
#define max_modules   1000
 
#define max_idents   5000
 
#define max_sections   4000 \
 
#define hash_size   353
 
#define buf_size   200
 
#define longest_name   1000 \
 
#define long_buf_size   (buf_size+longest_name)
 
#define local   static
 
#define array_size(a)   ((int)(sizeof(a)/sizeof(a[0])))
 
#define false   (boolean) 0
 
#define true   (boolean) 1
 
#define ctangle   0
 
#define cweave   1
 
#define and_and   04
 
#define lt_lt   020
 
#define gt_gt   021
 
#define plus_plus   013
 
#define minus_minus   01
 
#define minus_gt   031
 
#define not_eq   032
 
#define lt_eq   034
 
#define gt_eq   035
 
#define eq_eq   036
 
#define or_or   037
 
#define find_char()   (loc<=limit || get_line())
 
#define id_index(p)   ((sixteen_bits)((p)-id_table))
 
#define id_at(i)   (&id_table[i])
 
#define mod_index(p)   ((sixteen_bits)((p)-mod_table))
 
#define mod_at(i)   (&mod_table[i])
 
#define name_begin(p)   ((p)->byte_start)
 
#define length(p)   ((int)(strlen(name_begin(p))))
 
#define name_end(p)   (name_begin(p)+length(p))
 
#define complete_name(p)   ((p)->byte_start[-1]=='\0')
 
#define print_mod(p)   printf(": <%s%s>",name_begin(p), complete_name(p) ? "" : "..." )
 
#define spotless   0
 
#define harmless_message   1
 
#define error_message   2
 
#define fatal_message   3
 
#define mark_harmless()   if (history==spotless) history=harmless_message; else
 
#define mark_error()   (history=error_message)
 
#define overflow(t)   fatal("\n! Sorry, %s capacity exceeded",t) \
 
#define confusion(s)   fatal("\n! This can't happen: %s",s)
 
#define show_banner   flags['b']
 
#define show_happiness   flags['h']
 
#define show_progress   flags['p']
 
#define show_stats   flags['s']
 
#define C_plus_plus   flags['+']
 
#define compatibility_mode   flags['c']
 
#define update_terminal()   fflush(stdout)
 
#define new_line()   putchar('\n')
 
#define term_write(string, leng)   printf("%.*s",(int)(leng),string)
 
#define tok_begin(p)   (p)->tok_start
 
#define tok_end(p)   ((p)+1)->tok_start
 
#define text_table_end   (&text_table[max_texts])
 
#define tok_mem_end   (&tok_mem[max_toks])
 
#define store_byte(c)   if (tok_ptr==tok_mem_end) overflow("token"); else *tok_ptr++=c
 
#define macro_flag   (text_table_end-1)
 
#define header_flag   text_table_end
 
#define next_sec(m)   ((m)->text_link)
 
#define equiv   equiv_or_xref
 
#define verb_quote   0x2
 
#define join   0x3
 
#define cur_repl   cur_state.repl_field
 
#define cur_byte   cur_state.byte_field
 
#define cur_end   cur_state.end_field
 
#define cur_sec   cur_state.sec_nr_field
 
#define cur_ind   cur_state.indent_field
 
#define cur_state   stack[0]
 
#define stack_end   (&stack[stack_size_max])
 
#define stack_empty()   (stack_ptr==&stack[0])
 
#define C_printf(format, x)   fprintf(C_file,format,x)
 
#define C_putc(c)   putc(c,C_file)
 
#define put_indent()   (indent_buffer[ind_i=cur_ind]='\0',C_printf("%s",indent_buffer))
 
#define append_white(c)
 
#define trans_limit   9
 
#define trans_of(c)   c_trans[(unsigned char)(c)-0x80]
 
#define translation_exists(c)   (trans_of(c)[0]!='\0')
 
#define comp_op(op)
 
#define code_of(c)   ccode[(unsigned char)(c)]
 
#define compress(char2, code)   if (*loc==char2) return ++loc,code
 
#define preproc_directive   0
 
#define section_body   1
 
#define report(k, c, m)   printf("%lu %ss (out of %lu)\n",(unsigned long)(c),k,(unsigned long)(m))
 

Typedefs

typedef struct text text
 
typedef struct texttext_pointer
 
typedef struct output_statestack_pointer
 

Enumerations

enum  { identifier =0x80, section_start, section_end, line_mark }
 
enum  { no_space, num_or_id, operator, literal }
 
enum  {
  ignore =0x80, id_code, constant, verbatim,
  at_sign_image, join_code, ord, control_text,
  include_preproc, char_trans, format, definition,
  header, begin_C, module_name, new_section
}
 

Functions

boolean names_match (id_pointer, char *, int, int)
 
void init_id_name (id_pointer, int)
 
void init_module_name (mod_pointer)
 
void phase_two (void)
 
void output (text_pointer)
 
void output_preproc_directives (void)
 
void C_newline (void)
 
void out_char (eight_bits)
 
boolean mark_line (void)
 
void phase_one (void)
 
int main (int argc, char **argv)
 
void store_two_bytes (sixteen_bits x)
 
void push_level (mod_pointer p)
 
void continue_or_pop_level (void)
 
eight_bits skip_ahead (void)
 
boolean skip_comment (boolean one_liner)
 
eight_bits get_next (void)
 
void scan_repl (eight_bits context)
 
void scan_section (void)
 

Variables

text text_table [max_texts]
 
text_pointer text_ptr =&text_table[0]
 
eight_bits tok_mem [max_toks]
 
eight_bitstok_ptr =&tok_mem[0]
 
text_pointer text_root =NULL
 
text_pointerlast_unnamed =&text_root
 
boolean atp_seen =false
 
mod_pointer output_file [max_files]
 
int output_file_count =0
 
output_state stack [stack_size_max]
 
stack_pointer stack_ptr
 
char indent_buffer [max_indent]
 
sixteen_bits ind_i
 
int cur_val
 
eight_bits out_state
 
boolean protect
 
char c_trans [UCHAR_MAX+1-0x80][trans_limit+1]
 
eight_bits ccode [UCHAR_MAX+1]
 
id_pointer cur_id
 
mod_pointer cur_mod
 
text_pointer cur_text
 
eight_bits next_control
 

Macro Definition Documentation

#define and_and   04
#define append_white (   c)
Value:
if (ind_i>=max_indent) overflow("indent buffer"); \
else indent_buffer[ind_i++]= isspace(c) ? c : ' '
char indent_buffer[max_indent]
Definition: ctangle.c:185
sixteen_bits ind_i
Definition: ctangle.c:187
#define max_indent
Definition: ctangle.c:7
#define overflow(t)
Definition: ctangle.c:62
#define array_size (   a)    ((int)(sizeof(a)/sizeof(a[0])))
#define banner   "This is CTANGLE (version "version_string")"
#define buf_size   200
#define C_plus_plus   flags['+']
#define C_printf (   format,
 
)    fprintf(C_file,format,x)
#define C_putc (   c)    putc(c,C_file)
#define code_of (   c)    ccode[(unsigned char)(c)]
#define comp_op (   op)
Value:
(C_printf(out_state==operator && line_output ? " %s" : "%s",op) \
,out_state=operator)
eight_bits out_state
Definition: ctangle.c:192
#define line_output
Definition: ctangle.c:9
#define C_printf(format, x)
Definition: ctangle.c:94
#define compatibility_mode   flags['c']
#define complete_name (   p)    ((p)->byte_start[-1]=='\0')
#define compress (   char2,
  code 
)    if (*loc==char2) return ++loc,code
#define confusion (   s)    fatal("\n! This can't happen: %s",s)
#define ctangle   0
#define cur_byte   cur_state.byte_field
#define cur_end   cur_state.end_field
#define cur_ind   cur_state.indent_field
#define cur_repl   cur_state.repl_field
#define cur_sec   cur_state.sec_nr_field
#define cur_state   stack[0]
#define cweave   1
#define eq_eq   036
#define equiv   equiv_or_xref
#define error_message   2
#define false   (boolean) 0
#define fatal_message   3
#define find_char ( )    (loc<=limit || get_line())
#define gt_eq   035
#define gt_gt   021
#define harmless_message   1
#define hash_size   353
#define header_flag   text_table_end
#define id_at (   i)    (&id_table[i])
#define id_index (   p)    ((sixteen_bits)((p)-id_table))
#define join   0x3
#define length (   p)    ((int)(strlen(name_begin(p))))
#define line_output   flags['l']
#define local   static
#define long_buf_size   (buf_size+longest_name)
#define longest_name   1000 \
#define lt_eq   034
#define lt_lt   020
#define macro_flag   (text_table_end-1)
#define mark_error ( )    (history=error_message)
#define mark_harmless ( )    if (history==spotless) history=harmless_message; else
#define max_bytes   50000L \
#define max_files   50
#define max_idents   5000
#define max_indent   1000
#define max_modules   1000
#define max_sections   4000 \
#define max_texts   2500
#define max_toks   150000L
#define minus_gt   031
#define minus_minus   01
#define mod_at (   i)    (&mod_table[i])
#define mod_index (   p)    ((sixteen_bits)((p)-mod_table))
#define name_begin (   p)    ((p)->byte_start)
#define name_end (   p)    (name_begin(p)+length(p))
#define new_line ( )    putchar('\n')
#define next_sec (   m)    ((m)->text_link)
#define not_eq   032
#define or_or   037
#define overflow (   t)    fatal("\n! Sorry, %s capacity exceeded",t) \
#define plus_plus   013
#define preproc_directive   0
#define print_mod (   p)    printf(": <%s%s>",name_begin(p), complete_name(p) ? "" : "..." )
#define put_indent ( )    (indent_buffer[ind_i=cur_ind]='\0',C_printf("%s",indent_buffer))
#define report (   k,
  c,
 
)    printf("%lu %ss (out of %lu)\n",(unsigned long)(c),k,(unsigned long)(m))
#define section_body   1
#define show_banner   flags['b']
#define show_happiness   flags['h']
#define show_progress   flags['p']
#define show_stats   flags['s']
#define spotless   0
#define stack_empty ( )    (stack_ptr==&stack[0])
#define stack_end   (&stack[stack_size_max])
#define stack_size_max   50
#define store_byte (   c)    if (tok_ptr==tok_mem_end) overflow("token"); else *tok_ptr++=c
#define term_write (   string,
  leng 
)    printf("%.*s",(int)(leng),string)
#define text_table_end   (&text_table[max_texts])
#define tok_begin (   p)    (p)->tok_start
#define tok_end (   p)    ((p)+1)->tok_start
#define tok_mem_end   (&tok_mem[max_toks])
#define trans_limit   9
#define trans_of (   c)    c_trans[(unsigned char)(c)-0x80]
#define translation_exists (   c)    (trans_of(c)[0]!='\0')
#define true   (boolean) 1
#define update_terminal ( )    fflush(stdout)
#define variant   text
#define verb_quote   0x2
#define version_string   "x3.6"

Typedef Documentation

typedef struct output_state * stack_pointer
typedef struct text text
typedef struct text* text_pointer

Enumeration Type Documentation

anonymous enum
Enumerator
identifier 
section_start 
section_end 
line_mark 
anonymous enum
Enumerator
no_space 
num_or_id 
operator 
literal 
anonymous enum
Enumerator
ignore 
id_code 
constant 
verbatim 
at_sign_image 
join_code 
ord 
control_text 
include_preproc 
char_trans 
format 
definition 
header 
begin_C 
module_name 
new_section 

Function Documentation

void C_newline ( void  )
void continue_or_pop_level ( void  )
int get_next ( void  )
void init_id_name ( id_pointer  dummy,
int  ilk 
)
void init_module_name ( mod_pointer  node)
int main ( int  argc,
char **  argv 
)
boolean mark_line ( void  )
boolean names_match ( id_pointer  x,
char *  q,
int  l,
int  dummy 
)
void out_char ( eight_bits  c)
void output ( text_pointer  repl)
void output_preproc_directives ( void  )
void phase_one ( void  )
void phase_two ( void  )
void push_level ( mod_pointer  p)
void scan_repl ( eight_bits  context)
void scan_section ( void  )
eight_bits skip_ahead ( void  )
boolean skip_comment ( boolean  one_liner)
void store_two_bytes ( sixteen_bits  x)

Variable Documentation

boolean atp_seen =false
char c_trans[UCHAR_MAX+1-0x80][trans_limit+1]
eight_bits ccode[UCHAR_MAX+1]
id_pointer cur_id
mod_pointer cur_mod
text_pointer cur_text
int cur_val
sixteen_bits ind_i
char indent_buffer[max_indent]
text_pointer* last_unnamed =&text_root
eight_bits next_control
eight_bits out_state
mod_pointer output_file[max_files]
int output_file_count =0
boolean protect
stack_pointer stack_ptr
text_pointer text_ptr =&text_table[0]
text_pointer text_root =NULL
text text_table[max_texts]
eight_bits tok_mem[max_toks]
eight_bits* tok_ptr =&tok_mem[0]