Run through clang-format.

This commit is contained in:
David Given 2016-08-21 20:08:05 +02:00
parent 44b6421519
commit 2b2bd93e44

View file

@ -8,7 +8,6 @@
* I C _ L I B . C * I C _ L I B . C
*/ */
#include <stdio.h> #include <stdio.h>
#include <em_spec.h> #include <em_spec.h>
#include <em_pseu.h> #include <em_pseu.h>
@ -23,26 +22,27 @@
#include "../share/files.h" #include "../share/files.h"
#include "ic_lib.h" #include "ic_lib.h"
STATIC skip_string(n) STATIC skip_string(n)
offset n; offset n;
{ {
/* Read a string of length n and void it */ /* Read a string of length n and void it */
while (n--) { while (n--)
{
readchar(); readchar();
} }
} }
STATIC skip_arguments() STATIC skip_arguments()
{ {
/* Skip the arguments of a MES pseudo. The argument /* Skip the arguments of a MES pseudo. The argument
* list is terminated by a sp_cend byte. * list is terminated by a sp_cend byte.
*/ */
for (;;) { for (;;)
switch(table2()) { {
switch (table2())
{
case sp_scon: case sp_scon:
get_off(); /* void */ get_off(); /* void */
/* fall through !!! */ /* fall through !!! */
@ -60,10 +60,7 @@ STATIC skip_arguments()
} }
} }
STATIC bool proc_wanted(name) char* name;
STATIC bool proc_wanted(name)
char *name;
{ {
/* See if 'name' is the name of an external procedure /* See if 'name' is the name of an external procedure
* that has been used before, but for which no body * that has been used before, but for which no body
@ -72,18 +69,17 @@ STATIC bool proc_wanted(name)
proc_p p; proc_p p;
if (( p = proclookup(name,IMPORTING)) != (proc_p) 0 && if ((p = proclookup(name, IMPORTING)) != (proc_p)0 && !(p->p_flags1 & PF_BODYSEEN))
!(p->p_flags1 & PF_BODYSEEN)) { {
return TRUE; return TRUE;
} else { }
else
{
return FALSE; return FALSE;
} }
} }
STATIC bool data_wanted(name) char* name;
STATIC bool data_wanted(name)
char *name;
{ {
/* See if 'name' is the name of an externally visible /* See if 'name' is the name of an externally visible
* data block that has been used before, but for which * data block that has been used before, but for which
@ -92,16 +88,16 @@ STATIC bool data_wanted(name)
dblock_p db; dblock_p db;
if ((db = symlookup(name,IMPORTING)) != (dblock_p) 0 && if ((db = symlookup(name, IMPORTING)) != (dblock_p)0 && db->d_pseudo == DUNKNOWN)
db->d_pseudo == DUNKNOWN) { {
return TRUE; return TRUE;
} else { }
else
{
return FALSE; return FALSE;
} }
} }
STATIC bool wanted_names() STATIC bool wanted_names()
{ {
/* Read the names of procedures and data labels, /* Read the names of procedures and data labels,
@ -114,10 +110,13 @@ STATIC bool wanted_names()
* no defining occurrence has been met. * no defining occurrence has been met.
*/ */
for (;;) { for (;;)
switch(table2()) { {
switch (table2())
{
case DLBX: case DLBX:
if (data_wanted(string)) { if (data_wanted(string))
{
return TRUE; return TRUE;
} }
/* A data entity with the name /* A data entity with the name
@ -125,7 +124,8 @@ STATIC bool wanted_names()
*/ */
break; break;
case sp_pnam: case sp_pnam:
if (proc_wanted(string)) { if (proc_wanted(string))
{
return TRUE; return TRUE;
} }
break; break;
@ -137,8 +137,6 @@ STATIC bool wanted_names()
} }
} }
STATIC FILE* curfile = NULL; STATIC FILE* curfile = NULL;
STATIC bool useful() STATIC bool useful()
{ {
@ -150,29 +148,32 @@ STATIC bool useful()
* of the entities imported. * of the entities imported.
*/ */
for (;;) { for (;;)
if (table1() != PSEU || tabval != ps_mes) { {
if (table1() != PSEU || tabval != ps_mes)
{
error("cannot find MES %d in library file", ms_ext); error("cannot find MES %d in library file", ms_ext);
} }
if (table2() != CSTX1) { if (table2() != CSTX1)
{
error("message number expected"); error("message number expected");
} }
if (tabval == ms_ext) { if (tabval == ms_ext)
{
/* This is the one we searched */ /* This is the one we searched */
return wanted_names(); return wanted_names();
/* Read the names of the imported entities /* Read the names of the imported entities
* and check if any of them is wanted. * and check if any of them is wanted.
*/ */
} else { }
else
{
skip_arguments(); /* skip remainder of this MES */ skip_arguments(); /* skip remainder of this MES */
} }
} }
} }
STATIC bool is_archive(name) char* name;
STATIC bool is_archive(name)
char *name;
{ {
/* See if 'name' is the name of an archive file, i.e. it /* See if 'name' is the name of an archive file, i.e. it
* should end on ".ma" and should at least be four characters * should end on ".ma" and should at least be four characters
@ -181,12 +182,11 @@ STATIC bool is_archive(name)
register char* p; register char* p;
for (p = name; *p; p++); for (p = name; *p; p++)
;
return (p > name + 3) && (*--p == 'a') && (*--p == 'm') && (*--p == '.'); return (p > name + 3) && (*--p == 'a') && (*--p == 'm') && (*--p == '.');
} }
STATIC struct ar_hdr hdr; STATIC struct ar_hdr hdr;
STATIC bool read_hdr() STATIC bool read_hdr()
@ -199,33 +199,35 @@ STATIC bool read_hdr()
register int i; register int i;
fread(c, AR_TOTAL, 1, curfile); fread(c, AR_TOTAL, 1, curfile);
if (feof(curfile)) return 0; if (feof(curfile))
return 0;
i = 14; i = 14;
while (i--) { while (i--)
{
*p++ = *c++; *p++ = *c++;
} }
#define get2(c) (((c)[0] & 0377) | ((unsigned)((c)[1] & 0377) << 8)) #define get2(c) (((c)[0] & 0377) | ((unsigned)((c)[1] & 0377) << 8))
hdr.ar_date = ((long) get2(c)) << 16; c += 2; hdr.ar_date = ((long)get2(c)) << 16;
hdr.ar_date |= ((long) get2(c)) & 0xffff; c += 2; c += 2;
hdr.ar_date |= ((long)get2(c)) & 0xffff;
c += 2;
hdr.ar_uid = *c++; hdr.ar_uid = *c++;
hdr.ar_gid = *c++; hdr.ar_gid = *c++;
hdr.ar_mode = get2(c); c += 2; hdr.ar_mode = get2(c);
hdr.ar_size = (long) get2(c) << 16; c += 2; c += 2;
hdr.ar_size = (long)get2(c) << 16;
c += 2;
hdr.ar_size |= (long)get2(c) & 0xffff; hdr.ar_size |= (long)get2(c) & 0xffff;
return 1; return 1;
} }
STATIC int argcnt = ARGSTART - 1; STATIC int argcnt = ARGSTART - 1;
STATIC short arstate = NO_ARCHIVE; STATIC short arstate = NO_ARCHIVE;
FILE* next_file(argc, argv) int argc;
FILE *next_file(argc,argv)
int argc;
char* argv[]; char* argv[];
{ {
/* See if there are more EM input files. The file names /* See if there are more EM input files. The file names
@ -239,58 +241,75 @@ FILE *next_file(argc,argv)
long ptr; long ptr;
for (;;) { for (;;)
{
/* This loop is only exited via a return */ /* This loop is only exited via a return */
if (arstate == ARCHIVE) { if (arstate == ARCHIVE)
{
/* We were reading an archive file */ /* We were reading an archive file */
if (ftell(curfile) & 1) { if (ftell(curfile) & 1)
{
/* modules in an archive file always /* modules in an archive file always
* begin on a word boundary, i.e. at * begin on a word boundary, i.e. at
* an even address. * an even address.
*/ */
fseek(curfile, 1L, 1); fseek(curfile, 1L, 1);
} }
if (read_hdr()) { /* read header of next module */ if (read_hdr())
{ /* read header of next module */
ptr = ftell(curfile); /* file position */ ptr = ftell(curfile); /* file position */
file_init(curfile, ARCHIVE, hdr.ar_size); file_init(curfile, ARCHIVE, hdr.ar_size);
/* tell i/o package that we're reading /* tell i/o package that we're reading
* an archive module of given length. * an archive module of given length.
*/ */
if (useful()) { if (useful())
{
/* re-initialize file, because 'useful' /* re-initialize file, because 'useful'
* has read some bytes too. * has read some bytes too.
*/ */
fseek(curfile, ptr, 0); /* start module */ fseek(curfile, ptr, 0); /* start module */
file_init(curfile, ARCHIVE, hdr.ar_size); file_init(curfile, ARCHIVE, hdr.ar_size);
return curfile; return curfile;
} else { }
else
{
/* skip this module */ /* skip this module */
fseek(curfile, fseek(curfile,
ptr + hdr.ar_size, 0); ptr + hdr.ar_size, 0);
} }
} else { }
else
{
/* done with this archive */ /* done with this archive */
arstate = NO_ARCHIVE; arstate = NO_ARCHIVE;
} }
} else { }
else
{
/* open next file, close old */ /* open next file, close old */
if (curfile != NULL) { if (curfile != NULL)
{
fclose(curfile); fclose(curfile);
} }
argcnt++; argcnt++;
if (argcnt >= argc) { if (argcnt >= argc)
{
/* done with all arguments */ /* done with all arguments */
return NULL; return NULL;
} }
filename = argv[argcnt]; filename = argv[argcnt];
if ((curfile = fopen(filename,"r")) == NULL) { if ((curfile = fopen(filename, "r")) == NULL)
{
error("cannot open %s", filename); error("cannot open %s", filename);
} }
if (is_archive(filename)) { if (is_archive(filename))
{
/* ends on '.ma' */ /* ends on '.ma' */
arstate = ARCHIVE; arstate = ARCHIVE;
arch_init(curfile); /* read magic ar number */ arch_init(curfile); /* read magic ar number */
} else { }
else
{
file_init(curfile, NO_ARCHIVE, 0L); file_init(curfile, NO_ARCHIVE, 0L);
return curfile; return curfile;
} }