예제 #1
0
void
exit(void)
{
    if (tioc_valid)
        (void)tcsetattr(0, TCSADRAIN, &tioc);
    uexit(0);
}
예제 #2
0
파일: luatex.c 프로젝트: live-clones/luatex
string normalize_quotes(const_string name, const_string mesg)
{
    boolean quoted = false;
    boolean must_quote = (strchr(name, ' ') != NULL);
    /* Leave room for quotes and NUL. */
    string ret = (string) xmalloc((unsigned) strlen(name) + 3);
    string p;
    const_string q;
    p = ret;
    if (must_quote)
        *p++ = '"';
    for (q = name; *q; q++) {
        if (*q == '"')
            quoted = !quoted;
        else
            *p++ = *q;
    }
    if (must_quote)
        *p++ = '"';
    *p = '\0';
    if (quoted) {
        fprintf(stderr, "! Unbalanced quotes in %s %s\n", mesg, name);
        uexit(1);
    }
    return ret;
}
예제 #3
0
파일: main.c 프로젝트: luigiScarso/mflua
string 
cmdline P1C(int, n)
{
  if (n >= argc)
    { /* This error message should never happen, because the callers
         should always check they've got the arguments they expect.  */
      fprintf (stderr, "%s: Oops; not enough arguments.\n", argv[0]);
      uexit (1);
    }
  return argv[n];
}
예제 #4
0
int check_fclose (FILE * f)
{
  if (f == NULL)
    return 0;

  if (ferror(f) || fclose (f))
  {
    perrormod("\n! I/O Error");
    uexit(EXIT_FAILURE);
  }

  return 0;
}
예제 #5
0
/* Call usage if the program exits by printing the help message.
   MESSAGE is an NULL-terminated array or strings which make up the
   help message.  Each string is printed on a separate line.
   We use arrays instead of a single string to work around compiler
   limitations (sigh).
*/
void
usagehelp P1C(const_string*, message)
{
    extern KPSEDLL char *kpse_bug_address;

    while (*message) {
        fputs(*message, stdout);
        putchar('\n');
        ++message;
    }
    putchar('\n');
    fputs(kpse_bug_address, stdout);
    uexit(0);
}
예제 #6
0
void
printversionandexit (const_string banner,
                     const_string copyright_holder,  
                     const_string author,
                     char *extra_info)
{
  string prog_name;
  unsigned len;
  const_string prog_name_end = strchr (banner, ',');
  const_string prog_version = strrchr (banner, ' ');
  assert (prog_name_end && prog_version);
  prog_version++;
  
  len = prog_name_end - banner - sizeof ("This is");
  prog_name = xmalloc (len + 1);
  strncpy (prog_name, banner + sizeof ("This is"), len);
  prog_name[len] = 0;

  /* The Web2c version string starts with a space.  */
#ifdef PTEX
  printf ("%s %s (%s)%s\n", prog_name, prog_version, get_enc_string(),
          versionstring);
#else
  printf ("%s %s%s\n", prog_name, prog_version, versionstring);
#endif
  puts (kpathsea_version_string);
#ifdef PTEX
  puts (ptexenc_version_string);
#endif

  if (copyright_holder) {
    printf ("Copyright 2010 %s.\n", copyright_holder);
    if (!author)
      author = copyright_holder;
  }

  puts ("There is NO warranty.  Redistribution of this software is");
  fputs ("covered by the terms of ", stdout);
  printf ("both the %s copyright and\n", prog_name);
  puts ("the Lesser GNU General Public License.");
  puts ("For more information about these matters, see the file");
  printf ("named COPYING and the %s source.\n", prog_name);
  printf ("Primary author of %s: %s.\n", prog_name, author);

  if (extra_info) {
    puts (extra_info);
  }

  uexit (0);
}
예제 #7
0
static void display_version(void) {
	uint8_t min, maj;

	MOD_VERSION(MODULE_IVER, maj, min);

	INF("%s version `%s' using module version %d.%02d build options [%s ]", TARGETNAME, VERSION, maj, min, BUILDOPTS);
#ifdef HAVE_PCAP_LIB_VERSION
	INF("pcap version %s", pcap_lib_version());
#endif
	INF("%s", COMPILE_STR);
	INF("report bugs to %s", BUGURL);

	uexit(0);
}
예제 #8
0
static void
remove_newline P1C(string, s)
{
  char *temp = strrchr (s, '\n');
  if (temp == NULL)
    {
      fprintf (stderr, "Lost newline somehow.\n");
      /* This is so the convert script can delete the output file on error.  */
      puts ("@error@");
      uexit (1);
    }

  *temp = 0;
}
예제 #9
0
void
printversionandexit P4C(const_string, banner,
                        const_string, copyright_holder,
                        const_string, author,
                        char*, extra_info)
{
    extern string versionstring;           /* from web2c/lib/version.c */
    extern KPSEDLL string kpathsea_version_string;/* from kpathsea/version.c */
    string prog_name;
    unsigned len;
    const_string prog_name_end = strchr (banner, ',');
    const_string prog_version = strrchr (banner, ' ');
    assert (prog_name_end && prog_version);
    prog_version++;

    len = prog_name_end - banner - sizeof ("This is");
    prog_name = (string)xmalloc (len + 1);
    strncpy (prog_name, banner + sizeof ("This is"), len);
    prog_name[len] = 0;

    /* The Web2c version string starts with a space.  */
    printf ("%s %s%s\n", prog_name, prog_version, versionstring);
    puts (kpathsea_version_string);

    if (copyright_holder) {
        printf ("Copyright 2008 %s.\n", copyright_holder);
        if (!author)
            author = copyright_holder;
    }

    puts ("Kpathsea is copyright 2008 Karl Berry and Olaf Weber.");

    puts ("There is NO warranty.  Redistribution of this software is");
    fputs ("covered by the terms of ", stdout);
    printf ("both the %s copyright and\n", prog_name);
    puts ("the Lesser GNU General Public License.");
    puts ("For more information about these matters, see the file");
    printf ("named COPYING and the %s source.\n", prog_name);
    printf ("Primary author of %s: %s.\n", prog_name, author);
    puts ("Kpathsea written by Karl Berry, Olaf Weber, and others.\n");

    if (extra_info) {
        puts (extra_info);
    }

    uexit (0);
}
예제 #10
0
void
printversionandexit P3C(const_string, banner,
                        const_string, copyright_holder,  const_string, author)
{
  extern string versionstring;           /* from web2c/lib/version.c */
  extern KPSEDLL string kpathsea_version_string;/* from kpathsea/version.c */
  string prog_name;
  unsigned len;
  const_string prog_name_end = strchr (banner, ',');
  const_string prog_version = strrchr (banner, ' ');
  assert (prog_name_end && prog_version);
  prog_version++;
  
  len = prog_name_end - banner - sizeof ("This is");
  prog_name = (string)xmalloc (len + 1);
  strncpy (prog_name, banner + sizeof ("This is"), len);
  prog_name[len] = 0;

  /* The Web2c version string starts with a space.  */
  printf ("%s%s %s\n", prog_name, versionstring, prog_version);
  puts (kpathsea_version_string);

  if (copyright_holder) {
    printf ("Copyright (C) 1997-2003 %s.\n", copyright_holder);
    if (!author)
      author = copyright_holder;
  }

  puts ("Kpathsea is copyright (C) 1997-2003 Free Software Foundation, Inc.");

  puts ("There is NO warranty.  Redistribution of this software is");
  fputs ("covered by the terms of ", stdout);
  /* DVIcopy is GPL'd, so no additional words needed. */
  if (/*copyright_holder && */!STREQ (prog_name, "DVIcopy")) {
    printf ("both the %s copyright and\n", prog_name);
  }
  puts ("the GNU General Public License.");
  puts ("For more information about these matters, see the files");
  printf ("named COPYING and the %s source.\n", prog_name);
  printf ("Primary author of %s: %s.\n", prog_name, author);
  puts ("Kpathsea written by Karl Berry and others.\n");

  uexit (0);
}
예제 #11
0
파일: u1.c 프로젝트: thomdabeast/CS460-1
main(int argc, char *argv[])
{ 
  char name[64]; int pid, cmd, segment, i, active;
  pid = getpid();
  color = 0x000B + (pid % 5);  // avoid black on black baground

  printf("enter main() : argc = %d\n", argc);
  for (i=0; i<argc; i++)
    printf("argv[%d] = %s\n", i, argv[i]);
 
  while(1){
       pid = getpid(); 
       active = getmode();
       color = 0x000B + (pid % 5);
       segment = (pid+1)*0x1000;   
       printf("==============================================\n");
       printf("I am proc %din U mode: segment=%x active=%d\n", 
            pid, segment,active);
       show_menu();
       printf("Command ? ");
       gets(name); 
       if (name[0]==0) 
           continue;

       cmd = find_cmd(name);

       switch(cmd){
           case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : uswitch();  break;
           case 5 : uwait();    break;

           case 6 : uexit();    break;
           case 7 : ufork();    break;
           case 8 : uexec();    break;

           default: invalid(name); break;
       } 
  }
}
예제 #12
0
__dead void
panic(const char *fmt, ...)
{
    extern void closeall(void);
    va_list ap;
    static int paniced;

    if (!paniced) {
        paniced = 1;
        closeall();
    }

    va_start(ap, fmt);
    vprintf(fmt, ap);
    printf("\n");
    va_end(ap);
#if 0
    _rtt();
#else
    uexit(0);
#endif
    /*NOTREACHED*/
}
예제 #13
0
static void
ipc_snd (int n, int is_eof, char *data)
{
  struct
  {
    struct msg msg;
    char more_data[1024];
  } ourmsg;

  if (!ipc_is_open ()) {
    return;
  }

#ifdef IPC_DEBUG
  fprintf(stderr, "%d\t%d\n", ourmsg.msg.namelength, ourmsg.msg.eof);
  fputs ("tex: Sending message to socket ...\n", stderr);
#endif
  ourmsg.msg.namelength = n;
  ourmsg.msg.eof = is_eof;
  if (n) {
    strcpy (ourmsg.more_data, data);
  }
  n += sizeof (struct msg);
#ifdef IPC_DEBUG
  fprintf(stderr, "%d\t%d\n", ourmsg.msg.namelength, ourmsg.msg.eof);
  fputs ("tex: Writing to socket...\n", stderr);
#endif
#if defined(WIN32)
  if (send (sock, (char *)&ourmsg, n, 0) != n) {
#else
  if (write (sock, &ourmsg, n) != n) {
#endif
    ipc_close_out ();
  }
#ifdef IPC_DEBUG
  fputs ("tex: IPC message sent.\n", stderr);
#endif
}

/* This routine notifies the server if there is an eof, or the filename
   if a new DVI file is starting.  This is the routine called by TeX.
   Aleph defines str_start(#) as str_start_ar[# - too_big_char], with
   too_big_char = biggest_char + 1 = 65536 (omstr.ch).  */

void
ipcpage (int is_eof)
{
  static boolean begun = false;
  unsigned len = 0;
  string p = NULL;

  if (!begun) {
    string name; /* Just the filename.  */
    string cwd = xgetcwd ();

    ipc_open_out ();

    /* Have to pass whole filename to the other end, since it may have
       been started up and running as a daemon, e.g., as with the NeXT
       preview program.  */
    name = static_pdf->file_name;
    p = concat3 (cwd, DIR_SEP_STRING, name);
    free (cwd);
    free (name);

#if defined (WIN32)
    { char *q;
      for (q = p; *q; q++) {
        if (*q == '\\')
          *q = '/';
        else if (IS_KANJI(q))
          q++;
      }
    }
#endif
    len = strlen(p);
    begun = true;
  }
  ipc_snd (len, is_eof, p);

  if (p)
    free (p);
}
#endif /* TeX && IPC */

/* Normalize quoting of filename -- that is, only quote if there is a space,
   and always use the quote-name-quote style. */
string normalize_quotes(const_string name, const_string mesg)
{
    boolean quoted = false;
    boolean must_quote = (strchr(name, ' ') != NULL);
    /* Leave room for quotes and NUL. */
    string ret = (string) xmalloc((unsigned) strlen(name) + 3);
    string p;
    const_string q;
    p = ret;
    if (must_quote)
        *p++ = '"';
    for (q = name; *q; q++) {
        if (*q == '"')
            quoted = !quoted;
        else
            *p++ = *q;
    }
    if (must_quote)
        *p++ = '"';
    *p = '\0';
    if (quoted) {
        fprintf(stderr, "! Unbalanced quotes in %s %s\n", mesg, name);
        uexit(1);
    }
    return ret;
}
예제 #14
0
void recv_packet(void) {
	char errbuf[PCAP_ERRBUF_SIZE], *pfilter=NULL;
	struct bpf_program filter;
	bpf_u_int32 net, mask;
	int ac_s=0, ret=0, worktodo=1;
	uint8_t msg_type=0, status=0, *ptr=NULL;
	size_t msg_len=0;
	xpoll_t spdf[2];
	union {
		recv_workunit_t *r;
		uint8_t *cr;
		uint32_t *magic;
	} wk_u;
	union {
		listener_info_t *l;
		uint8_t *ptr;
	} l_u;
	union {
		drone_version_t *v;
		uint8_t *ptr;
	} d_u;
	drone_version_t dv;
	struct pcap_stat pcs;

	r_queue=fifo_init();

	close_output_modules();
	close_report_modules();
	close_payload_modules();

	DBG(M_IPC, "creating server socket");

	memset(s->ss, 0, sizeof(scan_settings_t));

	memset(&dv, 0, sizeof(dv));
	d_u.v=&dv;
	dv.magic=DRONE_MAGIC;
	dv.maj=DRONE_MAJ;
	dv.min=DRONE_MIN;
	recv_stats_t recv_stats;

	/* heh */
	if ((ac_s=socktrans_bind(s->ipcuri)) < 0) {
		terminate("cant create listener socket");
	}

	DBG(M_IPC, "waiting for main to connect");

	parent_sync();

	lc_s=socktrans_accept(ac_s, DEF_SOCK_TIMEOUT);
	if (lc_s < 0) {
		terminate("main didnt connect, exiting");
	}

	DBG(M_IPC, "got connection");

	if (get_singlemessage(lc_s, &msg_type, &status, &ptr, &msg_len) != 1) {
		terminate("unexpected sequence of messages from parent waiting for ident request, exiting");
	}

	if (msg_type != MSG_IDENT || status != MSG_STATUS_OK) {
		ERR("got an unknown message type `%s' or bad status %d from parent, exiting", strmsgtype(msg_type), status);
	}

	if (send_message(lc_s, MSG_IDENTLISTENER, MSG_STATUS_OK, d_u.ptr, sizeof(drone_version_t)) < 0) {
		terminate("cant send back msgident to parent");
	}

	if (get_singlemessage(lc_s, &msg_type, &status, &ptr, &msg_len) != 1) {
		terminate("cant read ident ack message from parent, exiting");
	}
	if (msg_type != MSG_ACK || status != MSG_STATUS_OK) {
		ERR("got an unknown message type `%s' or bad status %d from parent, exiting", strmsgtype(msg_type), status);
	}

	DBG(M_IPC, "sending ready message to parent");

	l_u.l=(listener_info_t *)xmalloc(sizeof(listener_info_t));

	memcpy(&l_u.l->myaddr, &s->vi[0]->myaddr, sizeof(struct sockaddr_storage));
	memcpy(&l_u.l->mymask, &s->vi[0]->mymask, sizeof(struct sockaddr_storage));
	memcpy(l_u.l->hwaddr, s->vi[0]->hwaddr, THE_ONLY_SUPPORTED_HWADDR_LEN);
	l_u.l->mtu=s->vi[0]->mtu;

	assert(s->interface_str != NULL);

	if (pcap_lookupnet(s->interface_str, &net, &mask, errbuf) < 0) {
		ERR("pcap_lookupnet fails, ignoring: %s", errbuf);
	}

	if (s->pcap_readfile == NULL) {
		pdev=pcap_open_live(s->interface_str, /* XXX haha */ s->vi[0]->mtu + 64, (GET_PROMISC() ? 1 : 0), 0, errbuf);
		if (pdev == NULL) {
			ERR("pcap open live: %s", errbuf);

			DBG(M_IPC, "sending ready error message to parent");
			if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
				terminate("cant send message ready error");
			}
			terminate("informed parent, exiting");
		}
	}
	else {
		pdev=pcap_open_offline(s->pcap_readfile, errbuf);
		if (pdev == NULL) {
			ERR("pcap open offline: %s", errbuf);

			DBG(M_IPC, "sending ready error message to parent");
			if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
				terminate("cant send message ready error");
			}
			terminate("informed parent, exiting");
		}
	}

	ret=util_getheadersize(pdev, errbuf);
	if (ret < 0 || ret > 0xffff) {
		ERR("error getting link header size: %s", errbuf);

		DBG(M_IPC, "sending ready error message to parent");
		if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
			terminate("cant send message ready error");
		}
		terminate("informed parent, exiting");
	}
	s->ss->header_len=(uint16_t)ret;

	if (s->pcap_dumpfile != NULL) {
		VRB(0, "opening `%s' for pcap log", s->pcap_dumpfile);
		pdump=pcap_dump_open(pdev, s->pcap_dumpfile);
		if (pdump == NULL) {
			ERR("cant log to pcap file `%s'", pcap_geterr(pdev));

			DBG(M_IPC, "sending ready error message to parent");
			if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
				terminate("cant send message ready error");
			}
			terminate("informed parent, exiting");
		}
	}
	else {
		DBG(M_CLD, "not logging to pcap file");
	}

	if (util_preparepcap(pdev, errbuf) < 0) {
		ERR("cant setup pcap filedesc to immediate mode: %s", errbuf);

		DBG(M_IPC, "sending ready error message to parent");
		if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
			terminate("cant send message ready error");
		}
		terminate("informed parent, exiting");
	}

	/* pcap_fd will be -1 for a pcap file */
	pcap_fd=pcap_get_selectable_fd(pdev);

	if (pcap_fd < 0 && s->pcap_readfile == NULL) {
		ERR("cant get selectable fd from pcap device, exiting");

		DBG(M_IPC, "sending ready error message to parent");
		if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
			terminate("sant send message ready error");
		}
		terminate("informed parent, exiting");
	}

#ifdef PCAP_D_IN
	if (pcap_setdirection(pdev, PCAP_D_IN) < 0) {
		ERR("cant set pcap direction to in, exiting");

		DBG(M_IPC, "sending ready error message to parent");
		if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
			terminate("sant send message ready error");
		}
		terminate("informed parent, exiting");
	}
#endif

	DBG(M_CLD, "listener dropping privs");

	if (drop_privs() < 0) {
		terminate("cant drop privs");
	}

	if (send_message(lc_s, MSG_READY, MSG_STATUS_OK, l_u.ptr, sizeof(listener_info_t)) < 0) {
		terminate("cant send message ready");
	}

	xfree(l_u.l);

	/* XXX */
	s->ss->syn_key=0;

	do {
		if (get_singlemessage(lc_s, &msg_type, &status, &wk_u.cr, &msg_len) != 1) {
			terminate("unexpected sequence of messages from parent looking for a workunit");
		}

		if (status != MSG_STATUS_OK) {
			terminate("bad message status %u", status);
		}

		if (msg_type == MSG_QUIT) {
			worktodo=0;
			break;
		}
		else if (msg_type == MSG_WORKUNIT) {
			;
		}
		else {
			terminate("unexpected message, expecting workunit or quit message");
		}

		if (msg_len < sizeof(uint32_t)) {
			terminate("bad message, too short [" STFMT "]", msg_len);
		}

		if (msg_len < sizeof(recv_workunit_t)) {
			terminate("short workunit");
		}

		worktodo=1;

		DBG(M_WRK, "workunit `%s'", strworkunit(wk_u.cr, msg_len));

		s->ss->recv_timeout=wk_u.r->recv_timeout;
		s->ss->ret_layers=wk_u.r->ret_layers;
		s->recv_opts=wk_u.r->recv_opts;
		s->ss->window_size=wk_u.r->window_size;

		s->ss->syn_key=wk_u.r->syn_key;

		if (wk_u.r->pcap_len) {
			if ((msg_len - sizeof(recv_workunit_t)) == wk_u.r->pcap_len) {
				extract_pcapfilter(wk_u.cr + sizeof(recv_workunit_t), wk_u.r->pcap_len);
			}
			else {
				terminate("pcap option length illegal");
			}
		}

		switch (*wk_u.magic) {
			case UDP_RECV_MAGIC:
				s->ss->mode=MODE_UDPSCAN;
				break;

			case TCP_RECV_MAGIC:
				s->ss->mode=MODE_TCPSCAN;
				break;

			case ARP_RECV_MAGIC:
				s->ss->mode=MODE_ARPSCAN;
				break;

			default:
				terminate("unknown recv workunit type");
				break;
		}

		DBG(M_IPC, "from ipc, got workunit: %s", strworkunit((const void *)wk_u.cr, msg_len));

		if (s->ss->mode == MODE_ARPSCAN) {
			if (s->ss->header_len != 14) {

				DBG(M_IPC, "sending msg error");
				if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
					terminate("cant send message ready");
				}
				terminate("wrong linktype for arp scan");
			}
		}

		if (s->ss->ret_layers > 0) {
			DBG(M_CLD, "setting up packet queue");
			p_queue=fifo_init();
		}

		pfilter=get_pcapfilterstr();

		VRB(1, "using pcap filter: `%s'", pfilter);

		memset(&filter, 0, sizeof(filter));
		if (pcap_compile(pdev, &filter, pfilter, 0, net) < 0) {
			ERR("error compiling filter: %s",  pcap_geterr(pdev));

			if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
				ERR("cant send message ready error");
			}
			terminate("cant compile pcap filter");
		}

		if (pcap_setfilter(pdev, &filter) < 0) {
			ERR("error setting compiled filter: %s", pcap_geterr(pdev));

			if (send_message(lc_s, MSG_READY, MSG_STATUS_ERROR, NULL, 0) < 0) {
				ERR("cant send message ready error");
			}
			terminate("cant set compiled pcap filter");
		}

		pcap_freecode(&filter);

		if (s->ss->ret_layers > 0) {
			DBG(M_IPC, "returning whole packet via ipc");
		}

		DBG(M_IPC, "sending ready message to parent");

		if (pcap_setnonblock(pdev, 1, errbuf) < 0) {
			terminate("cant set pcap non-blocking mode");
		}

		if (send_message(lc_s, MSG_READY, MSG_STATUS_OK, NULL, 0) < 0) {
			terminate("cant send message ready");
		}

		while (1) {
			spdf[0].fd=lc_s;
			spdf[1].fd=pcap_fd;

			/* if pdev is a socket  ( ! -1 ) */
			if (xpoll(&spdf[0], 2, -1) < 0) {
				ERR("xpoll fails: %s", strerror(errno));
			}

			if (spdf[1].rw & XPOLL_READABLE) {
				pcap_dispatch(pdev, 1, parse_packet, NULL);
			}

			/* no packets, better drain the queue */
			drain_pqueue();

			if (spdf[0].rw & XPOLL_READABLE) {
				if (get_singlemessage(lc_s, &msg_type, &status, &ptr, &msg_len) != 1) {
					ERR("unexpected sequence of messages from parent in main read loop, exiting");
					worktodo=0;
					break;
				}

				if (msg_type == MSG_TERMINATE) {
					DBG(M_IPC, "parent wants me to stop listening, breaking");
					break;
				}
				else if (msg_type == MSG_QUIT) {
					DBG(M_IPC, "Parent wants me to quit, breaking");
					worktodo=0;
					break;
				}
				else {
					ERR("got strange message `%s' from parent, exiting", strmsgtype(msg_type));
					worktodo=0;
					break;
				}
			}
		}

		memset(&recv_stats, 0, sizeof(recv_stats));

		if (pcap_stats(pdev, &pcs) != -1) {

			recv_stats.packets_recv=pcs.ps_recv;
			recv_stats.packets_dropped=pcs.ps_drop;
			recv_stats.packets_dropped=pcs.ps_ifdrop;
		}

		if (send_message(lc_s, MSG_WORKDONE, MSG_STATUS_OK, (void *)&recv_stats, sizeof(recv_stats)) < 0) {
			terminate("cant send workdone message to parent, exiting");
		}

	} while (worktodo);

	pcap_close(pdev);
	if (s->pcap_dumpfile) {
		pcap_dump_close(pdump);
	}


	DBG(M_CLD, "listener exiting");

	shutdown(lc_s, SHUT_RDWR);
	close(lc_s);
 
	uexit(0);
}
예제 #15
0
int
main P2C(int, argc,  string *, argv)
{
  register char *cp;
  int blanks_done, indent, i;
  char *program_name = "";

  kpse_set_program_name (argv[0], NULL); /* In case we use FATAL.  */

  for (i = 1; i < argc; i++)
    {
      if (STREQ(argv[i],"-t"))
	tex = true;
      else
	program_name = argv[i];
    }

  while (fgets (buf, BUFSIZ, stdin))
    {
      remove_newline (buf);
      blanks_done = false;

      for (cp = buf; *cp; ++cp) ;

      while (cp != buf && *--cp == ' ') ;

      while (*cp == '.')
	{
	  join (cp + 1);
	  while (*cp)
	    ++cp;
	  while (*--cp == ' ') ;
	}

      for (cp = buf, indent = 0; *cp == ' ' || *cp == '\t'; ++cp)
	{
	  if (*cp == ' ')
	    indent++;
	  else
	    indent += 8;
	}

      if (!*cp)
	{			/* All blanks, possibly with "{" */
	  puts (buf);
	  continue;
	}
      if (*cp == '{')

        {
	  do_blanks (indent);
	  putchar ('{');
	  ++cp;
	  while (*cp == ' ' || *cp == '\t')
	    ++cp;
	  blanks_done = true;
	  if (!*cp)
	    {
	      putchar ('\n');
	      continue;
	    }
	}

      if (!blanks_done)
	do_blanks (indent);

      if (strncmp (cp, "read ( input", 12) == 0)
	{
	  char variable_name[20];
	  if (sscanf (cp, "read ( input , %s )", variable_name) != 1)
            {
  	      fprintf (stderr, "sscanf failed\n");
              uexit (1);
            }
	  printf ("%s = getint();\n", variable_name);
	  continue;
	}

      if (strncmp (cp, "lab", 3) == 0 && strchr (cp, ':'))
	{
	  do
	    {
	      putchar (*cp);
	    }
          while (*cp++ != ':');

          while (*cp == ' ')
	    ++cp;
	  putchar (' ');
	}

      if (strncmp (cp, "else write", 10) == 0)
	{
	  puts ("else");
	  do_blanks (indent);
	  cp += 5;
	  while (*cp == ' ')
	    ++cp;
	}

      if (bare (cp, '{'))
	{
	  while (*cp != '{')
	    {
	      putchar (*cp);
	      ++cp;
	    }
	  ++cp;
	  puts ("{");
	  indent += 4;
	  do_blanks (indent);
	  while (*cp == ' ')
	    ++cp;
	}

      if (strncmp (cp, "write (", 7) && strncmp (cp, "writeln (", 9))
	{
	  /* if not a write/writeln, just copy it to stdout and continue */
	  puts (cp);
	  continue;
	}
      cmd = cp;
      while (!whole (buf))	/* make sure we have whole stmt */
	{
	  fgets (&buf[strlen (buf)], BUFSIZ - strlen (buf), stdin);
	  remove_newline (buf);
	}

      while (*cp != '(')
	++cp;
      ++cp;
      while (*(cp + 1) == ' ')
	++cp;

      /* Some writes start with a variable, instead of a file. */
      if (*(cp + 1) == '"' || *(cp + 1) == '\''
          || strncmp (cp + 1, "buffer", 6) == 0
          || strncmp (cp + 1, "xchr", 4) == 0
          || strncmp (cp + 1, "k ,", 3) == 0
          || strncmp (cp + 1, "s ,", 3) == 0
          || strncmp (cp + 1, "dig", 3) == 0
          || strncmp (cp + 1, "HEX", 3) == 0
          || strncmp (cp + 1, "versionstring", 13) == 0
          || strncmp (cp + 1, "kpathseaversionstring", 21) == 0
         )
	strcpy (filename, "stdout");
      else
	{
	  file = filename;
	  while (*cp != ',' && *cp != ')')
	    *file++ = *cp++;
	  *file = '\0';
	}
      if (*cp == ')')
	{
	  printf ("putc%s ('\\n', %s);\n", oem, filename);
	  continue;
	}
      argp = ++cp;
      as = args;
      while (*cp == ' ')
	++cp;
      while (*cp != ')')
	{
	  if (*cp == '\'' || strncmp (cp, "xchr", 4) == 0
              || (strncmp (cp ,"HEX", 3) == 0
                  && (STREQ (program_name, "ofm2opl")
                      || STREQ (program_name, "opl2ofm")
                      || STREQ (program_name, "ovp2ovf")
                      || STREQ (program_name, "ovf2ovp")))
	      || strncmp (cp, "ASCII04", 7) == 0
	      || strncmp (cp, "ASCII1", 6) == 0
	      || strncmp (cp, "ASCIIall", 8) == 0              
	      || strncmp (cp, "months", 6) == 0
	      || strncmp (cp, "nameoffile", 10) == 0
	      || (strncmp (cp, "buffer", 6) == 0
                  && (STREQ (program_name, "vptovf")
                      || STREQ (program_name, "pltotf")
                      || STREQ (program_name, "ovp2ovf")
                      || STREQ (program_name, "ofm2opl")))
              || (((strncmp (cp, "buf", 3) == 0
		    || strncmp (cp, "xdig", 4) == 0
		    || strncmp (cp, "xext", 4) == 0
		    || strncmp (cp, "xhyf", 4) == 0)
                  && STREQ (program_name, "patgen")))
             )
	    {
	      *as++ = '%';
	      *as++ = 'c';
	      if (tex && strncmp (cp, "xchr", 4) == 0)
		{
		  *cp = 'X';
		  cp = strchr (cp, '[');
		  *cp = '(';
		  cp = advance_cp(cp,1);
		  *cp++ = ')';
		}
	      else if (*cp == '\'')
		cp += 2;
	    }
          
	  else if (*cp == '"')
	    {
	      *as++ = '%';
	      *as++ = 's';
	      while (*++cp != '"')	/* skip to end of string */
		if (*cp == '\\')
		  ++cp;		/* allow \" in string */
	    }

          /* More kludge -- versionstring is a string, not a number, so
             we have to use %s.  */
          else if (strncmp (cp, "versionstring", 13) == 0)
            {
              *as++ = '%';
              *as++ = 's';
            }

          else
	    {
	      *as++ = '%';
	      *as++ = 'l';
	      *as++ = 'd';
	      cp = insert_long (cp);
	      cp = skip_balanced (cp);	/* It's a numeric expression */
	    }
	  while (*cp != ',' && *cp != ')')
	    ++cp;
	  while (*cp == ',' || *cp == ' ')
	    ++cp;
	}

      if (strncmp (cmd, "writeln", 7) == 0)
	{
	  *as++ = '\\';
	  *as++ = 'n';
	}

      *as = '\0';
      if (strcmp (args, "%c") == 0)
	{
	  for (as = argp; *as; ++as) ;
	  while (*--as != ')') ;
	  *as = '\0';
	  printf ("putc%s (%s, %s);\n", oem, argp, filename);
	}
      else if (STREQ (args, "%s"))
        printf ("Fputs%s (%s, %s\n", oem, filename, argp);
      else
        printf ("fprintf%s (%s, \"%s\", %s\n", oem, filename, args, argp);
    }

  return EXIT_SUCCESS;
}
예제 #16
0
int getconfig_argv(int argc, char ** argv) {
	int ch=0;
	char conffile[512];

#define OPTS	\
		"b:" "B:" "c" "d:" "D" "e:" "E" "F" "G:" "h" "H" "i:" "I" "j:" "l:" "L:" "m:" "M:" "o:" "p:" "P:" "q:" "Q" \
		"r:" "R:" "s:" "S" "t:" "T:" "u:" "U" "w:" "W:" "v" "V" "z" "Z:"

#ifdef WITH_LONGOPTS
	const struct option long_opts[]={
		{"broken-crc",		1, NULL, 'b'},
		{"source-port",		1, NULL, 'B'},
		{"proc-duplicates",	0, NULL, 'c'},
		{"delay-type",		1, NULL, 'd'},
		{"no-defpayload",	0, NULL, 'D'},
		{"enable-modules",	1, NULL, 'e'},
		{"show-errors",		0, NULL, 'E'},
		{"try-frags",		0, NULL, 'F'},
		{"payload-group",	1, NULL, 'G'},
		{"help",		0, NULL, 'h'},
		{"do-dns",		0, NULL, 'H'},
		{"interface",		1, NULL, 'i'},
		{"immediate",		0, NULL, 'I'},
		{"ignore-seq",		1, NULL, 'j'},
		{"logfile",		1, NULL, 'l'},
		{"packet-timeout",	1, NULL, 'L'},
		{"mode",		1, NULL, 'm'},
		{"module-dir",		1, NULL, 'M'},
		{"format",		1, NULL, 'o'},
		{"ports",		1, NULL, 'p'},
		{"pcap-filter",		1, NULL, 'P'},
		{"covertness",		1, NULL, 'q'},
		{"quiet",		0, NULL, 'Q'},
		{"pps",			1, NULL, 'r'},
		{"repeats",		1, NULL, 'R'},
		{"source-addr",		1, NULL, 's'},
		{"no-shuffle",		0, NULL, 'S'},
		{"ip-ttl",		1, NULL, 't'},
		{"ip-tos",		1, NULL, 'T'},
		{"debug",		1, NULL, 'u'},
		{"no-openclosed",	0, NULL, 'U'},
		{"savefile",		1, NULL, 'w'},
		{"fingerprint",		1, NULL, 'W'},
		{"verbose",		1, NULL, 'v'}, /* this is different in the long / short opts */
		{"version",		0, NULL, 'V'},
		{"sniff",		0, NULL, 'z'},
		{"drone-str",		1, NULL, 'Z'},
		{NULL,			0, NULL,  0 }
	};
#endif /* LONG OPTION SUPPORT */

	scan_setdefaults();

	snprintf(conffile, sizeof(conffile) -1, CONF_FILE, s->profile);
	if (readconf(conffile) < 0) {
		return -1;
	}

#ifdef WITH_LONGOPTS
	while ((ch=getopt_long(argc, argv, OPTS, long_opts, NULL)) != -1) {
#else
	while ((ch=getopt(argc, argv, OPTS)) != -1) {
#endif
		switch (ch) {
			case 'b':
				if (scan_setbroken(optarg) < 0) {
					usage();
				}
				break;

			case 'B':
				if (scan_setsrcp(atoi(optarg)) < 0) {
					usage();
				}
				break;

			case 'c':
				if (scan_setprocdups(1) < 0) {
					usage();
				}
				break;

			case 'D': /* set no default payload */
				if (scan_setdefpayload(0) < 0) {
					usage();
				}
				break;

			case 'd':
				if (scan_setdelaytype(atoi(optarg)) < 0) {
					usage();
				}
				break;

			case 'e': /* enable modules */
				if (scan_setenablemodule(optarg) < 0) {
					usage();
				}
				break;

			case 'E': /* report and listen for non open/closed responses */
				if (scan_setprocerrors(1) < 0) {
					usage();
				}
				break;

			case 'F': /* fragment packets if possible */
				if (scan_settryfrags(1) < 0) {
					usage();
				}
				break;

			case 'G':
				if (scan_setpayload_grp(atoi(optarg)) < 0) {
					usage();
				}
				break;

			case 'h': /* help */
				usage();
				break;

			case 'H': /* resolve ip addresses into names during reporting phase */
				if (scan_setdodns(1) < 0) {
					usage();
				}
				break;

			case 'i': /* interface name */
				if (scan_setinterface(optarg) < 0) {
					usage();
				}
				break;

			case 'I':
				if (scan_setimmediate(1) < 0) {
					usage();
				}
				break;

			case 'j': /* ignore sequence numbers during tcp scanning */
				if (scan_setignoreseq(optarg) < 0) {
					usage();
				}
				break;

			case 'L': /* how long to wait for replies after done sending */
				if (scan_setrecvtimeout(atoi(optarg)) < 0) {
					usage();
				}
				break;

			case 'l': /* log to file, not tty */
				if ((s->_stdout=fopen(optarg, "a+")) == NULL) {
					terminate("logfile `%s' cant be opened", optarg);
				}
				s->_stderr=s->_stdout;
				break;

			case 'm': /* scan mode, tcp udp, etc */
				if (scan_setoptmode(optarg) < 0) {
					usage();
				}
				break;

			case 'M': /* module directory base */
				if (scan_setmoddir(optarg) < 0) {
					usage();
				}
				break;

			case 'o': /* report format string */
				if (scan_setformat(optarg) < 0) {
					usage();
				}
				break;
			

			case 'p': /* Global ports to scan */
				if (scan_setgports(optarg) < 0) {
					usage();
				}
				break;

			case 'P': /* pcap filter to use, like "! port 162" */
				if (scan_setpcapfilter(optarg) < 0) {
					usage();
				}
				break;

			case 'q': /* covertness */
				if (scan_setcovertness(atoi(optarg)) < 0) {
					usage();
				}
				break;

			case 'Q':
				if (scan_setreportquiet(1) < 0) {
					usage();
				}
				break;

			case 'r': /* rate of scan */
				if (scan_setpps(optarg) < 0) {
					usage();
				}
				break;

			case 'R': /* repeat scan n times */
				if (scan_setrepeats(atoi(optarg)) < 0) {
					usage();
				}
				break;

			case 's': /* set source ip address to optarg */
				if (scan_setsrcaddr(optarg) < 0) {
					usage();
				}
				break;

			case 'S': /* do not shuffle ports */
				if (scan_setshuffle(1) < 0) {
					usage();
				}
				break;

			case 't': /* ttl on outgoing IP datagrams */
				if (scan_setttl(optarg) < 0) {
					usage();
				}
				break;

			case 'T': /* TOS on outgoing IP datagram */
				if (scan_settos(atoi(optarg)) < 0) {
					usage();
				}
				break;

			case 'u': /* debug mask */
				if (scan_setdebug(optarg) < 0) {
					usage();
				}
				break;

			case 'U': /* do NOT translate Open/Closed in output, display as is */
				if (scan_settrans(0) < 0) {
					usage();
				}
				break;

			case 'v': /* verbose */
				if (optarg != NULL) {
					if (scan_setverbose(atoi(optarg)) < 0) usage();
				}
				else if (scan_setverboseinc() < 0) {
					usage();
				}
				break;

			case 'V':
				display_version();
				break;

			case 'w': /* write to pcap logfile optarg */
				if (scan_setsavefile(optarg) < 0) {
					usage();
				}
				break;

			case 'W': /* what stack to pretend to have */
				if (scan_setfingerprint(atoi(optarg)) < 0) {
					usage();
				}
				break;

			case 'z': /* im too lazy to run tcpdump mode */
				if (scan_setsniff(1) < 0) {
					usage();
				}
				break;

			case 'Z': /* used for cluster scanning */
				if (scan_setdronestring(optarg) < 0) {
					usage();
				}
				break;

			default:
				usage();
				break;
		} /* switch option */
	} /* getopt loop */

	/* its not set if its null, so set it, otherwise it is */
	if (s->mod_dir == NULL) {
		scan_setmoddir(MODULE_DIR);
	}

	s->argv_ext=fifo_init();

	for (; optind < argc; optind++) {
		fifo_push(s->argv_ext, xstrdup(argv[optind]));
	}

	return 1;
}


void do_targets(void) {
	union {
		void *ptr;
		char *str;
	} s_u;
	char *estr=NULL;

	for (s_u.ptr=fifo_pop(s->argv_ext); s_u.ptr != NULL; s_u.ptr=fifo_pop(s->argv_ext)) {
		if (workunit_add(s_u.str, &estr) < 0) {
			if (access(s_u.str, R_OK) == 0) {
				FILE *rfile=NULL;
				char lbuf[2048];
				char *tok=NULL, *rent=NULL;

				CLEAR(lbuf);

				rfile=fopen(s_u.str, "r");
				if (rfile == NULL) {
					continue;
				}

				while (fgets(lbuf, sizeof(lbuf) -1, rfile) != NULL) {
					for (tok=strtok_r(lbuf, "\t\r\n\v\f ", &rent); tok != NULL; tok=strtok_r(NULL, "\t\r\n\v\f ", &rent)) {
						if (workunit_add(tok, &estr) < 0) {
							ERR("cant add workunit `%s' from file `%s': %s", tok, s_u.str, estr);
						}
					}
				}

				fclose(rfile);
			}
			else {
				ERR("cant add workunit for argument `%s': %s", s_u.str, estr != NULL ? estr : ""); /* bad hostname? */
			}
		}
	}

	/* if we are not a drone */
	if (!(GET_LISTENDRONE() || GET_SENDDRONE())) {
		if (s->num_hosts < 1) {
			INF("What should i scan? I've got nothing to do.\n");
			usage();
			uexit(0);
		}
	}

	return;
}

static void usage(void) {

	INF("%s (version %s)\n"
   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	"USAGE: %s [Options] Target List (ex. X.X.X.X/YY:S-E)\n"
	"-b, --broken-crc Broken CRC sums on [T]ransport, [N]etwork, or both[TN].\n"
	"-B, --source-port Source port.\n"
	"-c, --proc-duplicates Process duplicate replies.\n"
	"-d, --delay-type Delay type `%s'.\n"
	"-D, --no-defpayload  Only probe known protocols.\n"
	"-e, --enable-module  A comma separated list of modules to activate.\n"
	"-E, --proc-errors Process `non-open' responses. (ICMP errors, TCP RST, etc.).\n"
	"-G, --payload-group Group number TCP/UDP payload type selection (default all).\n"
	"-h, --help Help.\n"
	"-H, --do-dns Resolve hostnames during the reporting phase.\n"
	"-i, --interface Optional interface name, like eth0 or fxp1.\n"
	"-I, --immediate Display things as we find them.\n"
	"-j, --ignore-seq Ignore `A'll, 'R'eset sequence numbers for TCP header\n"
	"\t\tvalidation.\n"
	"-l, --logfile Write to this file not my terminal.\n"
	"-L, --packet-timeout Wait this long for packets to come back, default\n"
	"\t\tis %d secs.\n"
	"-m, --mode Scan mode, TCP/SYN scan is default, options are [U]DP, [T]CP,\n"
	"\t\tand [sf]TCP Connect. For -mT you can also specify tcp flags\n"
	"\t\tlike -mTsFpU for example that would send TCP SYN packets with\n"
	"\t\t(NO Syn|FIN|NO Push|URG)\n"
	"-M, --module-dir Modules directory.\n"
	"-o, --format Reply format, see man page for format specification\n"
	"-p, --ports Global ports to scan, if not specified in target options.\n"
	"-P, --pcap-filter Extra pcap filter string for reciever.\n"
	"-q, --covertness Covertness value from 0 to 255.\n"
	"-Q, --quiet Disable output to the screen.\n"
	"-r, --pps Packets per second in total, not per host.\n"
	"-R, --repeats Repeat packet scan N times.\n"
	"-s, --source-addr Source address for packets, `r' for random.\n"
	"-S, --no-shuffle Do not shuffle ports.\n"
	"-t, --ip-ttl Set TTL on sent packets for example, 62, 6-16 or r64-128.\n"
	"-T, --ip-tos Set TOS on sent packets.\n"
	"-u, --debug Enable debug messages. According to user provided mask.\n"
	"-U, --no-openclosed Don't say open or closed in output.\n"
	"-w, --safefile Write pcap file of recieved packets.\n"
	"-W, --fingerprint Stack to pretend to have OS fingerprints:\n"
	"\t\t0=cisco(def) 1=openbsd 2=WindowsXP 3=p0fsendsyn 4=FreeBSD\n"
	"\t\t5=nmap 6=linux 7:strangetcp\n"
	"-v, --verbose Verbose output. Support for up to -vvvvv, for really verbose.\n"
	"-V, --version Display version\n"
	"-z, --sniff Display packet parsing information.\n"
	"-Z, --drone-str Undocumented feature.\n\n"
	"Examples:\n"
	"Address ranges are CIDR like 1.2.3.4/8 for all of 1.?.?.?\n"
	"if you omit the CIDR mask then /32 is implied.\n"
	"Port ranges are like 1-4096 with 53 only scanning one port,\n"
	"`a' for all 65k and `p' for 1-1024\n"
	"%s -i eth1 -Ir 160 -E 192.168.1.0/24:1-4000 gateway:a\n\n"
	"Type `man %s` for more information about usage.",
	PROGNAME, VERSION, PROGNAME, delay_getopts(), DEF_SCANTIMEOUT, PROGNAME, PROGNAME);

	uexit(0);
}
예제 #17
0
  /* 10 */ smallnumber c  ;
  c = curmod ;
  if ( jobname == 0 ) 
  openlogfile () ;
  while ( inputptr > 0 ) if ( ( curinput .indexfield > 15 ) ) 
  endtokenlist () ;
  else endfilereading () ;
  while ( loopptr != 0 ) stopiteration () ;
  while ( openparens > 0 ) {
      
    print ( 1078 ) ;
    decr ( openparens ) ;
  } 
  while ( condptr != 0 ) {
      
    printnl ( 1079 ) ;
    printcmdmod ( 2 , curif ) ;
    if ( ifline != 0 ) 
    {
      print ( 1080 ) ;
      printint ( ifline ) ;
    } 
    print ( 1081 ) ;
    ifline = mem [condptr + 1 ].cint ;
    curif = mem [condptr ].hhfield .b1 ;
    loopptr = condptr ;
    condptr = mem [condptr ].hhfield .v.RH ;
    freenode ( loopptr , 2 ) ;
  } 
  if ( history != 0 ) {
      
    if ( ( ( history == 1 ) || ( interaction < 3 ) ) ) {
	
      if ( selector == 3 ) 
      {
	selector = 1 ;
	printnl ( 1082 ) ;
	selector = 3 ;
      } 
    } 
  } 
  if ( c == 1 ) 
  {
	;
#ifdef INIMF
    if ( iniversion ) 
    {
      storebasefile () ;
      goto lab10 ;
    } 
#endif /* INIMF */
    printnl ( 1083 ) ;
    goto lab10 ;
  } 
  lab10: ;
} 
#ifdef INIMF
void 
initprim ( void ) 
{
  primitive ( 409 , 41 , 1 ) ;
  primitive ( 410 , 41 , 2 ) ;
  primitive ( 411 , 41 , 3 ) ;
  primitive ( 412 , 41 , 4 ) ;
  primitive ( 413 , 41 , 5 ) ;
  primitive ( 414 , 41 , 6 ) ;
  primitive ( 415 , 41 , 7 ) ;
  primitive ( 416 , 41 , 8 ) ;
  primitive ( 417 , 41 , 9 ) ;
  primitive ( 418 , 41 , 10 ) ;
  primitive ( 419 , 41 , 11 ) ;
  primitive ( 420 , 41 , 12 ) ;
  primitive ( 421 , 41 , 13 ) ;
  primitive ( 422 , 41 , 14 ) ;
  primitive ( 423 , 41 , 15 ) ;
  primitive ( 424 , 41 , 16 ) ;
  primitive ( 425 , 41 , 17 ) ;
  primitive ( 426 , 41 , 18 ) ;
  primitive ( 427 , 41 , 19 ) ;
  primitive ( 428 , 41 , 20 ) ;
  primitive ( 429 , 41 , 21 ) ;
  primitive ( 430 , 41 , 22 ) ;
  primitive ( 431 , 41 , 23 ) ;
  primitive ( 432 , 41 , 24 ) ;
  primitive ( 433 , 41 , 25 ) ;
  primitive ( 434 , 41 , 26 ) ;
  primitive ( 435 , 41 , 27 ) ;
  primitive ( 436 , 41 , 28 ) ;
  primitive ( 437 , 41 , 29 ) ;
  primitive ( 438 , 41 , 30 ) ;
  primitive ( 439 , 41 , 31 ) ;
  primitive ( 440 , 41 , 32 ) ;
  primitive ( 441 , 41 , 33 ) ;
  primitive ( 442 , 41 , 34 ) ;
  primitive ( 443 , 41 , 35 ) ;
  primitive ( 444 , 41 , 36 ) ;
  primitive ( 445 , 41 , 37 ) ;
  primitive ( 446 , 41 , 38 ) ;
  primitive ( 447 , 41 , 39 ) ;
  primitive ( 448 , 41 , 40 ) ;
  primitive ( 449 , 41 , 41 ) ;
  primitive ( 408 , 48 , 0 ) ;
  primitive ( 91 , 64 , 0 ) ;
  eqtb [9760 ]= eqtb [cursym ];
  primitive ( 93 , 65 , 0 ) ;
  primitive ( 125 , 66 , 0 ) ;
  primitive ( 123 , 47 , 0 ) ;
  primitive ( 58 , 82 , 0 ) ;
  eqtb [9762 ]= eqtb [cursym ];
  primitive ( 459 , 81 , 0 ) ;
  primitive ( 460 , 80 , 0 ) ;
  primitive ( 461 , 78 , 0 ) ;
  primitive ( 44 , 83 , 0 ) ;
  primitive ( 59 , 84 , 0 ) ;
  eqtb [9763 ]= eqtb [cursym ];
  primitive ( 92 , 7 , 0 ) ;
  primitive ( 462 , 19 , 0 ) ;
  primitive ( 463 , 73 , 0 ) ;
  primitive ( 464 , 60 , 0 ) ;
  primitive ( 465 , 33 , 0 ) ;
  bgloc = cursym ;
  primitive ( 466 , 58 , 0 ) ;
  primitive ( 467 , 20 , 0 ) ;
  primitive ( 468 , 61 , 0 ) ;
  primitive ( 469 , 28 , 0 ) ;
  primitive ( 470 , 12 , 0 ) ;
  primitive ( 453 , 85 , 0 ) ;
  eqtb [9767 ]= eqtb [cursym ];
  egloc = cursym ;
  primitive ( 471 , 27 , 0 ) ;
  primitive ( 472 , 6 , 0 ) ;
  primitive ( 473 , 10 , 0 ) ;
  primitive ( 474 , 71 , 0 ) ;
  primitive ( 475 , 74 , 0 ) ;
  primitive ( 476 , 14 , 0 ) ;
  primitive ( 477 , 15 , 0 ) ;
  primitive ( 478 , 16 , 0 ) ;
  primitive ( 479 , 70 , 0 ) ;
  primitive ( 480 , 29 , 0 ) ;
  primitive ( 481 , 25 , 0 ) ;
  primitive ( 482 , 9 , 0 ) ;
  primitive ( 483 , 13 , 0 ) ;
  primitive ( 484 , 8 , 0 ) ;
  primitive ( 485 , 18 , 0 ) ;
  primitive ( 486 , 79 , 0 ) ;
  primitive ( 487 , 75 , 0 ) ;
  primitive ( 488 , 36 , 0 ) ;
  primitive ( 489 , 59 , 0 ) ;
  primitive ( 490 , 72 , 0 ) ;
  primitive ( 491 , 76 , 0 ) ;
  primitive ( 656 , 17 , 1 ) ;
  primitive ( 657 , 17 , 2 ) ;
  primitive ( 658 , 17 , 54 ) ;
  primitive ( 659 , 17 , 45 ) ;
  primitive ( 660 , 17 , 50 ) ;
  primitive ( 454 , 17 , 0 ) ;
  eqtb [9765 ]= eqtb [cursym ];
  primitive ( 661 , 4 , 9770 ) ;
  primitive ( 662 , 4 , 9920 ) ;
  primitive ( 663 , 4 , 1 ) ;
  primitive ( 455 , 4 , 0 ) ;
  eqtb [9764 ]= eqtb [cursym ];
  primitive ( 664 , 62 , 0 ) ;
  primitive ( 665 , 62 , 1 ) ;
  primitive ( 64 , 62 , 2 ) ;
  primitive ( 666 , 62 , 3 ) ;
  primitive ( 677 , 57 , 9770 ) ;
  primitive ( 678 , 57 , 9920 ) ;
  primitive ( 679 , 57 , 10070 ) ;
  primitive ( 680 , 57 , 1 ) ;
  primitive ( 681 , 57 , 2 ) ;
  primitive ( 682 , 57 , 3 ) ;
  primitive ( 692 , 3 , 0 ) ;
  primitive ( 618 , 3 , 1 ) ;
  primitive ( 719 , 1 , 1 ) ;
  primitive ( 452 , 2 , 2 ) ;
  eqtb [9766 ]= eqtb [cursym ];
  primitive ( 720 , 2 , 3 ) ;
  primitive ( 721 , 2 , 4 ) ;
  primitive ( 347 , 34 , 30 ) ;
  primitive ( 348 , 34 , 31 ) ;
  primitive ( 349 , 34 , 32 ) ;
  primitive ( 350 , 34 , 33 ) ;
  primitive ( 351 , 34 , 34 ) ;
  primitive ( 352 , 34 , 35 ) ;
  primitive ( 353 , 34 , 36 ) ;
  primitive ( 354 , 34 , 37 ) ;
  primitive ( 355 , 35 , 38 ) ;
  primitive ( 356 , 35 , 39 ) ;
  primitive ( 357 , 35 , 40 ) ;
  primitive ( 358 , 35 , 41 ) ;
  primitive ( 359 , 35 , 42 ) ;
  primitive ( 360 , 35 , 43 ) ;
  primitive ( 361 , 35 , 44 ) ;
  primitive ( 362 , 35 , 45 ) ;
  primitive ( 363 , 35 , 46 ) ;
  primitive ( 364 , 35 , 47 ) ;
  primitive ( 365 , 35 , 48 ) ;
  primitive ( 366 , 35 , 49 ) ;
  primitive ( 367 , 35 , 50 ) ;
  primitive ( 368 , 35 , 51 ) ;
  primitive ( 369 , 35 , 52 ) ;
  primitive ( 370 , 35 , 53 ) ;
  primitive ( 371 , 35 , 54 ) ;
  primitive ( 372 , 35 , 55 ) ;
  primitive ( 373 , 35 , 56 ) ;
  primitive ( 374 , 35 , 57 ) ;
  primitive ( 375 , 35 , 58 ) ;
  primitive ( 376 , 35 , 59 ) ;
  primitive ( 377 , 35 , 60 ) ;
  primitive ( 378 , 35 , 61 ) ;
  primitive ( 379 , 35 , 62 ) ;
  primitive ( 380 , 35 , 63 ) ;
  primitive ( 381 , 35 , 64 ) ;
  primitive ( 382 , 35 , 65 ) ;
  primitive ( 383 , 35 , 66 ) ;
  primitive ( 384 , 35 , 67 ) ;
  primitive ( 385 , 37 , 68 ) ;
  primitive ( 43 , 44 , 69 ) ;
  primitive ( 45 , 44 , 70 ) ;
  primitive ( 42 , 56 , 71 ) ;
  primitive ( 47 , 55 , 72 ) ;
  eqtb [9761 ]= eqtb [cursym ];
  primitive ( 386 , 46 , 73 ) ;
  primitive ( 310 , 46 , 74 ) ;
  primitive ( 388 , 53 , 76 ) ;
  primitive ( 387 , 46 , 75 ) ;
  primitive ( 60 , 51 , 77 ) ;
  primitive ( 389 , 51 , 78 ) ;
  primitive ( 62 , 51 , 79 ) ;
  primitive ( 390 , 51 , 80 ) ;
  primitive ( 61 , 52 , 81 ) ;
  primitive ( 391 , 51 , 82 ) ;
  primitive ( 401 , 38 , 94 ) ;
  primitive ( 402 , 38 , 95 ) ;
  primitive ( 403 , 38 , 96 ) ;
  primitive ( 404 , 38 , 97 ) ;
  primitive ( 405 , 38 , 98 ) ;
  primitive ( 406 , 38 , 99 ) ;
  primitive ( 407 , 38 , 100 ) ;
  primitive ( 38 , 49 , 83 ) ;
  primitive ( 392 , 56 , 84 ) ;
  primitive ( 393 , 56 , 85 ) ;
  primitive ( 394 , 56 , 86 ) ;
  primitive ( 395 , 56 , 87 ) ;
  primitive ( 396 , 56 , 88 ) ;
  primitive ( 397 , 56 , 89 ) ;
  primitive ( 398 , 56 , 90 ) ;
  primitive ( 399 , 56 , 91 ) ;
  primitive ( 400 , 46 , 92 ) ;
  primitive ( 340 , 31 , 15 ) ;
  primitive ( 326 , 31 , 4 ) ;
  primitive ( 324 , 31 , 2 ) ;
  primitive ( 331 , 31 , 9 ) ;
  primitive ( 328 , 31 , 6 ) ;
  primitive ( 333 , 31 , 11 ) ;
  primitive ( 335 , 31 , 13 ) ;
  primitive ( 336 , 31 , 14 ) ;
  primitive ( 913 , 86 , 0 ) ;
  primitive ( 914 , 86 , 1 ) ;
  primitive ( 273 , 24 , 0 ) ;
  primitive ( 274 , 24 , 1 ) ;
  primitive ( 275 , 24 , 2 ) ;
  primitive ( 920 , 24 , 3 ) ;
  primitive ( 921 , 22 , 0 ) ;
  primitive ( 922 , 22 , 1 ) ;
  primitive ( 936 , 23 , 0 ) ;
  primitive ( 937 , 23 , 1 ) ;
  primitive ( 938 , 23 , 2 ) ;
  primitive ( 939 , 23 , 3 ) ;
  primitive ( 940 , 23 , 4 ) ;
  primitive ( 957 , 69 , 1 ) ;
  primitive ( 958 , 69 , 0 ) ;
  primitive ( 959 , 69 , 2 ) ;
  primitive ( 960 , 67 , 6 ) ;
  primitive ( 961 , 67 , 16 ) ;
  primitive ( 962 , 68 , 0 ) ;
  primitive ( 963 , 68 , 1 ) ;
  primitive ( 993 , 26 , 0 ) ;
  primitive ( 994 , 26 , 1 ) ;
  primitive ( 995 , 26 , 2 ) ;
  primitive ( 1005 , 21 , 0 ) ;
  primitive ( 1006 , 21 , 1 ) ;
  primitive ( 1007 , 21 , 2 ) ;
  primitive ( 1008 , 21 , 3 ) ;
  primitive ( 1009 , 21 , 4 ) ;
  primitive ( 1027 , 77 , 0 ) ;
  primitive ( 1028 , 77 , 1 ) ;
  primitive ( 1029 , 77 , 5 ) ;
  primitive ( 1030 , 77 , 2 ) ;
  primitive ( 1031 , 77 , 6 ) ;
  primitive ( 1032 , 77 , 3 ) ;
  primitive ( 1033 , 77 , 7 ) ;
  primitive ( 1034 , 77 , 11 ) ;
  primitive ( 1035 , 77 , 128 ) ;
  primitive ( 1060 , 30 , 4 ) ;
  primitive ( 1061 , 30 , 16 ) ;
} 
void 
inittab ( void ) 
{
  integer k  ;
  rover = 23 ;
  mem [rover ].hhfield .v.RH = 268435455L ;
  mem [rover ].hhfield .lhfield = 1000 ;
  mem [rover + 1 ].hhfield .lhfield = rover ;
  mem [rover + 1 ].hhfield .v.RH = rover ;
  lomemmax = rover + 1000 ;
  mem [lomemmax ].hhfield .v.RH = 0 ;
  mem [lomemmax ].hhfield .lhfield = 0 ;
  {register integer for_end; k = memtop - 2 ;for_end = memtop ; if ( k <= 
  for_end) do 
    mem [k ]= mem [lomemmax ];
  while ( k++ < for_end ) ;} 
  avail = 0 ;
  memend = memtop ;
  himemmin = memtop - 2 ;
  varused = 23 ;
  dynused = memtop + 1 - himemmin ;
  intname [1 ]= 409 ;
  intname [2 ]= 410 ;
  intname [3 ]= 411 ;
  intname [4 ]= 412 ;
  intname [5 ]= 413 ;
  intname [6 ]= 414 ;
  intname [7 ]= 415 ;
  intname [8 ]= 416 ;
  intname [9 ]= 417 ;
  intname [10 ]= 418 ;
  intname [11 ]= 419 ;
  intname [12 ]= 420 ;
  intname [13 ]= 421 ;
  intname [14 ]= 422 ;
  intname [15 ]= 423 ;
  intname [16 ]= 424 ;
  intname [17 ]= 425 ;
  intname [18 ]= 426 ;
  intname [19 ]= 427 ;
  intname [20 ]= 428 ;
  intname [21 ]= 429 ;
  intname [22 ]= 430 ;
  intname [23 ]= 431 ;
  intname [24 ]= 432 ;
  intname [25 ]= 433 ;
  intname [26 ]= 434 ;
  intname [27 ]= 435 ;
  intname [28 ]= 436 ;
  intname [29 ]= 437 ;
  intname [30 ]= 438 ;
  intname [31 ]= 439 ;
  intname [32 ]= 440 ;
  intname [33 ]= 441 ;
  intname [34 ]= 442 ;
  intname [35 ]= 443 ;
  intname [36 ]= 444 ;
  intname [37 ]= 445 ;
  intname [38 ]= 446 ;
  intname [39 ]= 447 ;
  intname [40 ]= 448 ;
  intname [41 ]= 449 ;
  hashused = 9757 ;
  stcount = 0 ;
  hash [9768 ].v.RH = 451 ;
  hash [9766 ].v.RH = 452 ;
  hash [9767 ].v.RH = 453 ;
  hash [9765 ].v.RH = 454 ;
  hash [9764 ].v.RH = 455 ;
  hash [9763 ].v.RH = 59 ;
  hash [9762 ].v.RH = 58 ;
  hash [9761 ].v.RH = 47 ;
  hash [9760 ].v.RH = 91 ;
  hash [9759 ].v.RH = 41 ;
  hash [9757 ].v.RH = 456 ;
  eqtb [9759 ].lhfield = 63 ;
  mem [19 ].hhfield .lhfield = 9770 ;
  mem [19 ].hhfield .v.RH = 0 ;
  mem [memtop ].hhfield .lhfield = 268435455L ;
  mem [3 ].hhfield .lhfield = 0 ;
  mem [3 ].hhfield .v.RH = 0 ;
  mem [4 ].hhfield .lhfield = 1 ;
  mem [4 ].hhfield .v.RH = 0 ;
  {register integer for_end; k = 5 ;for_end = 11 ; if ( k <= for_end) do 
    mem [k ]= mem [4 ];
  while ( k++ < for_end ) ;} 
  mem [12 ].cint = 0 ;
  mem [0 ].hhfield .v.RH = 0 ;
  mem [0 ].hhfield .lhfield = 0 ;
  mem [1 ].cint = 0 ;
  mem [2 ].cint = 0 ;
  serialno = 0 ;
  mem [13 ].hhfield .v.RH = 13 ;
  mem [14 ].hhfield .lhfield = 13 ;
  mem [13 ].hhfield .lhfield = 0 ;
  mem [14 ].hhfield .v.RH = 0 ;
  mem [21 ].hhfield .b1 = 0 ;
  mem [21 ].hhfield .v.RH = 9768 ;
  eqtb [9768 ].v.RH = 21 ;
  eqtb [9768 ].lhfield = 42 ;
  eqtb [9758 ].lhfield = 92 ;
  hash [9758 ].v.RH = 736 ;
  mem [17 ].hhfield .b1 = 11 ;
  mem [20 ].cint = 1073741824L ;
  mem [16 ].cint = 0 ;
  mem [15 ].hhfield .lhfield = 0 ;
  if ( iniversion ) 
  baseident = 1070 ;
} 
#endif /* INIMF */
void mainbody( void ) {
    
  bounddefault = 250000L ;
  boundname = "main_memory" ;
  setupboundvariable ( addressof ( mainmemory ) , boundname , bounddefault ) ;
  bounddefault = 3000 ;
  boundname = "buf_size" ;
  setupboundvariable ( addressof ( bufsize ) , boundname , bounddefault ) ;
  bounddefault = 79 ;
  boundname = "error_line" ;
  setupboundvariable ( addressof ( errorline ) , boundname , bounddefault ) ;
  bounddefault = 50 ;
  boundname = "half_error_line" ;
  setupboundvariable ( addressof ( halferrorline ) , boundname , bounddefault 
  ) ;
  bounddefault = 79 ;
  boundname = "max_print_line" ;
  setupboundvariable ( addressof ( maxprintline ) , boundname , bounddefault ) 
  ;
  bounddefault = 768 ;
  boundname = "screen_width" ;
  setupboundvariable ( addressof ( screenwidth ) , boundname , bounddefault ) 
  ;
  bounddefault = 1024 ;
  boundname = "screen_depth" ;
  setupboundvariable ( addressof ( screendepth ) , boundname , bounddefault ) 
  ;
  bounddefault = 16384 ;
  boundname = "gf_buf_size" ;
  setupboundvariable ( addressof ( gfbufsize ) , boundname , bounddefault ) ;
  if ( errorline > 255 ) 
  errorline = 255 ;
  if ( screenwidth > 32767 ) 
  screenwidth = 32767 ;
  if ( screendepth > 32767 ) 
  screendepth = 32767 ;
  {
    if ( mainmemory < infmainmemory ) 
    mainmemory = infmainmemory ;
    else if ( mainmemory > supmainmemory ) 
    mainmemory = supmainmemory ;
  } 
  memtop = 0 + mainmemory - 1 ;
  memmax = memtop ;
  {
    if ( bufsize < infbufsize ) 
    bufsize = infbufsize ;
    else if ( bufsize > supbufsize ) 
    bufsize = supbufsize ;
  } 
  buffer = xmallocarray ( ASCIIcode , bufsize ) ;
  rowtransition = xmallocarray ( screencol , screenwidth ) ;
  gfbuf = xmallocarray ( eightbits , gfbufsize ) ;
  sourcefilenamestack = xmallocarray ( strnumber , 15 ) ;
  fullsourcefilenamestack = xmallocarray ( strnumber , 15 ) ;
#ifdef INIMF
  if ( iniversion ) 
  {
    mem = xmallocarray ( memoryword , memtop + 1 ) ;
  } 
#endif /* INIMF */
  mfluabeginprogram () ;
  history = 3 ;
  if ( readyalready == 314159L ) 
  goto lab1 ;
  bad = 0 ;
  if ( ( halferrorline < 30 ) || ( halferrorline > errorline - 15 ) ) 
  bad = 1 ;
  if ( maxprintline < 60 ) 
  bad = 2 ;
  if ( gfbufsize % 8 != 0 ) 
  bad = 3 ;
  if ( 1100 > memtop ) 
  bad = 4 ;
  if ( 7919 > 9500 ) 
  bad = 5 ;
  if ( headersize % 4 != 0 ) 
  bad = 6 ;
  if ( ( ligtablesize < 255 ) || ( ligtablesize > 32510 ) ) 
  bad = 7 ;
#ifdef INIMF
  if ( memmax != memtop ) 
  bad = 10 ;
#endif /* INIMF */
  if ( memmax < memtop ) 
  bad = 10 ;
  if ( ( 0 > 0 ) || ( 255 < 127 ) ) 
  bad = 11 ;
  if ( ( 0 > 0 ) || ( 268435455L < 32767 ) ) 
  bad = 12 ;
  if ( ( 0 < 0 ) || ( 255 > 268435455L ) ) 
  bad = 13 ;
  if ( ( 0 < 0 ) || ( memmax >= 268435455L ) ) 
  bad = 14 ;
  if ( maxstrings > 268435455L ) 
  bad = 15 ;
  if ( bufsize > 268435455L ) 
  bad = 16 ;
  if ( ( 255 < 255 ) || ( 268435455L < 65535L ) ) 
  bad = 17 ;
  if ( 9769 + maxinternal > 268435455L ) 
  bad = 21 ;
  if ( 10220 > 268435455L ) 
  bad = 22 ;
  if ( 15 * 11 > bistacksize ) 
  bad = 31 ;
  if ( 20 + 17 * 45 > bistacksize ) 
  bad = 32 ;
  if ( basedefaultlength > maxint ) 
  bad = 41 ;
  if ( bad > 0 ) 
  {
    fprintf ( stdout , "%s%s%ld\n",  "Ouch---my internal constants have been clobbered!" ,     "---case " , (long)bad ) ;
    goto lab9999 ;
  } 
  initialize () ;
#ifdef INIMF
  if ( iniversion ) 
  {
    if ( ! getstringsstarted () ) 
    goto lab9999 ;
    inittab () ;
    initprim () ;
    initstrptr = strptr ;
    initpoolptr = poolptr ;
    maxstrptr = strptr ;
    maxpoolptr = poolptr ;
    fixdateandtime () ;
  } 
#endif /* INIMF */
  readyalready = 314159L ;
  mfluaPREstartofMF () ;
  lab1: selector = 1 ;
  tally = 0 ;
  termoffset = 0 ;
  fileoffset = 0 ;
  fprintf ( stdout , "%s%s",  "This is MFLua, Version 2.7182818" , "-0.5" ) ;
  Fputs ( stdout ,  versionstring ) ;
  if ( baseident == 0 ) 
  fprintf ( stdout , "%s%s%c\n",  " (preloaded base=" , dumpname , ')' ) ;
  else {
      
    slowprint ( baseident ) ;
    println () ;
  } 
  if ( translatefilename ) 
  {
    putc ( '(' ,  stdout );
    fputs ( translatefilename , stdout ) ;
    { putc ( ')' ,  stdout );  putc ( '\n',  stdout ); }
  } 
  fflush ( stdout ) ;
  jobname = 0 ;
  logopened = false ;
  outputfilename = 0 ;
  {
    {
      inputptr = 0 ;
      maxinstack = 0 ;
      inopen = 0 ;
      openparens = 0 ;
      maxbufstack = 0 ;
      paramptr = 0 ;
      maxparamstack = 0 ;
      first = 1 ;
      curinput .startfield = 1 ;
      curinput .indexfield = 0 ;
      line = 0 ;
      curinput .namefield = 0 ;
      forceeof = false ;
      if ( ! initterminal () ) 
      goto lab9999 ;
      curinput .limitfield = last ;
      first = last + 1 ;
    } 
    scannerstatus = 0 ;
    if ( ( baseident == 0 ) || ( buffer [curinput .locfield ]== 38 ) ) 
    {
      if ( baseident != 0 ) 
      initialize () ;
      if ( ! openbasefile () ) 
      goto lab9999 ;
      if ( ! loadbasefile () ) 
      {
	wclose ( basefile ) ;
	goto lab9999 ;
      } 
      wclose ( basefile ) ;
      while ( ( curinput .locfield < curinput .limitfield ) && ( buffer [
      curinput .locfield ]== 32 ) ) incr ( curinput .locfield ) ;
    } 
    buffer [curinput .limitfield ]= 37 ;
    fixdateandtime () ;
    initrandoms ( ( internal [17 ]/ 65536L ) + internal [16 ]) ;
    if ( interaction == 0 ) 
    selector = 0 ;
    else selector = 1 ;
    if ( curinput .locfield < curinput .limitfield ) {
	
      if ( buffer [curinput .locfield ]!= 92 ) 
      startinput () ;
    } 
  } 
  history = 0 ;
  mfluainitialize () ;
  if ( startsym > 0 ) 
  {
    cursym = startsym ;
    backinput () ;
  } 
  mfluaPREmaincontrol () ;
  maincontrol () ;
  mfluaPOSTmaincontrol () ;
  finalcleanup () ;
  mfluaPOSTfinalcleanup () ;
  closefilesandterminate () ;
  lab9999: {
      
    fflush ( stdout ) ;
    readyalready = 0 ;
    if ( ( history != 0 ) && ( history != 1 ) ) 
    uexit ( 1 ) ;
    else uexit ( 0 ) ;
  } 
} 
예제 #18
0
void 
readpostamble ( void ) 
{
  integer k  ;
  integer p, q, m, u, v, w, c  ;
  postloc = curloc - 1 ;
  fprintf ( stdout , "%s%ld",  "Postamble starts at byte " , (long)postloc ) ;
  if ( postloc == gfprevptr ) 
  { putc ( '.' ,  stdout );  putc ( '\n',  stdout ); }
  else
  fprintf ( stdout , "%s%ld%c\n",  ", after special info at byte " , (long)gfprevptr , '.' ) 
  ;
  p = signedquad () ;
  if ( p != gfprevptr ) 
  {
    fprintf ( stdout , "%ld%s%s%s%ld%s%ld%s%ld%c",  (long)a , ": " , "! " , "backpointer in byte " , (long)curloc - 4 ,     " should be " , (long)gfprevptr , " not " , (long)p , '!' ) ;
    putc ('\n',  stdout );
  } 
  designsize = signedquad () ;
  checksum = signedquad () ;
  fprintf ( stdout , "%s%ld%s",  "design size = " , (long)designsize , " (" ) ;
  printscaled ( designsize / 16 ) ;
  fprintf ( stdout , "%s\n",  "pt)" ) ;
  fprintf ( stdout , "%s%ld\n",  "check sum = " , (long)checksum ) ;
  hppp = signedquad () ;
  vppp = signedquad () ;
  fprintf ( stdout , "%s%ld%s",  "hppp = " , (long)hppp , " (" ) ;
  printscaled ( hppp ) ;
  { putc ( ')' ,  stdout );  putc ( '\n',  stdout ); }
  fprintf ( stdout , "%s%ld%s",  "vppp = " , (long)vppp , " (" ) ;
  printscaled ( vppp ) ;
  { putc ( ')' ,  stdout );  putc ( '\n',  stdout ); }
  pixratio = ( designsize / ((double) 1048576L ) ) * ( hppp / ((double) 
  1048576L ) ) ;
  minmstated = signedquad () ;
  maxmstated = signedquad () ;
  minnstated = signedquad () ;
  maxnstated = signedquad () ;
  fprintf ( stdout , "%s%ld%s%ld\n",  "min m = " , (long)minmstated , ", max m = " , (long)maxmstated ) ;
  if ( minmstated > minmoverall ) 
  {
    fprintf ( stdout , "%ld%s%s%s%ld%c",  (long)a , ": " , "! " , "min m should be <=" , (long)minmoverall ,     '!' ) ;
    putc ('\n',  stdout );
  } 
  if ( maxmstated < maxmoverall ) 
  {
    fprintf ( stdout , "%ld%s%s%s%ld%c",  (long)a , ": " , "! " , "max m should be >=" , (long)maxmoverall ,     '!' ) ;
    putc ('\n',  stdout );
  } 
  fprintf ( stdout , "%s%ld%s%ld\n",  "min n = " , (long)minnstated , ", max n = " , (long)maxnstated ) ;
  if ( minnstated > minnoverall ) 
  {
    fprintf ( stdout , "%ld%s%s%s%ld%c",  (long)a , ": " , "! " , "min n should be <=" , (long)minnoverall ,     '!' ) ;
    putc ('\n',  stdout );
  } 
  if ( maxnstated < maxnoverall ) 
  {
    fprintf ( stdout , "%ld%s%s%s%ld%c",  (long)a , ": " , "! " , "max n should be >=" , (long)maxnoverall ,     '!' ) ;
    putc ('\n',  stdout );
  } 
  do {
      a = curloc ;
    k = getbyte () ;
    if ( ( k == 245 ) || ( k == 246 ) ) 
    {
      c = firstpar ( k ) ;
      if ( k == 245 ) 
      {
	u = signedquad () ;
	v = signedquad () ;
      } 
      else {
	  
	u = getbyte () * 65536L ;
	v = 0 ;
      } 
      w = signedquad () ;
      p = signedquad () ;
      fprintf ( stdout , "%s%ld%s%ld%s",  "Character " , (long)c , ": dx " , (long)u , " (" ) ;
      printscaled ( u ) ;
      if ( v != 0 ) 
      {
	fprintf ( stdout , "%s%ld%s",  "), dy " , (long)v , " (" ) ;
	printscaled ( v ) ;
      } 
      fprintf ( stdout , "%s%ld%s",  "), width " , (long)w , " (" ) ;
      w = round ( w * pixratio ) ;
      printscaled ( w ) ;
      fprintf ( stdout , "%s%ld\n",  "), loc " , (long)p ) ;
      if ( charptr [c ]== 0 ) 
      {
	fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " ,         "duplicate locator for this character!" ) ;
	putc ('\n',  stdout );
      } 
      else if ( p != charptr [c ]) 
      {
	fprintf ( stdout , "%ld%s%s%s%ld%c",  (long)a , ": " , "! " , "character location should be " ,         (long)charptr [c ], '!' ) ;
	putc ('\n',  stdout );
      } 
      charptr [c ]= 0 ;
      k = 244 ;
    } 
  } while ( ! ( k != 244 ) ) ;
  if ( k != 249 ) 
  {
    fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " , "should be postpost!" ) ;
    putc ('\n',  stdout );
  } 
  {register integer for_end; k = 0 ;for_end = 255 ; if ( k <= for_end) do 
    if ( charptr [k ]> 0 ) 
    {
      fprintf ( stdout , "%ld%s%s%s%ld%c",  (long)a , ": " , "! " , "missing locator for character " , (long)k       , '!' ) ;
      putc ('\n',  stdout );
    } 
  while ( k++ < for_end ) ;} 
  q = signedquad () ;
  if ( q != postloc ) 
  {
    fprintf ( stdout , "%ld%s%s%s%ld%s%ld%c",  (long)a , ": " , "! " , "postamble pointer should be " ,     (long)postloc , " not " , (long)q , '!' ) ;
    putc ('\n',  stdout );
  } 
  m = getbyte () ;
  if ( m != 131 ) 
  {
    fprintf ( stdout , "%ld%s%s%s%ld%s%ld%c",  (long)a , ": " , "! " , "identification byte should be " , (long)131     , ", not " , (long)m , '!' ) ;
    putc ('\n',  stdout );
  } 
  k = curloc ;
  m = 223 ;
  while ( ( m == 223 ) && ! eof ( gffile ) ) m = getbyte () ;
  if ( ! eof ( gffile ) ) 
  {
    fprintf ( stderr , "%s%s%ld%s%c\n",  "Bad GF file: " , "signature in byte " , (long)curloc - 1 ,     " should be 223" , '!' ) ;
    uexit ( 1 ) ;
  } 
  else if ( curloc < k + 4 ) 
  {
    fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " ,     "not enough signature bytes at end of file!" ) ;
    putc ('\n',  stdout );
  } 
} 
예제 #19
0
void
usage P1C(const_string, str)
{
  fprintf (stderr, "Try `%s --help' for more information.\n", str);
  uexit (1);
}
예제 #20
0
파일: regfix.c 프로젝트: luigiScarso/mflua
int
main P1H(void)
{
    register int i;
#ifdef	vax
    register char *cp;
#endif

    for (i=0; i<NUMTYPES; i++)
	lens[i] = strlen(types[i]);

    /* Copy the declarations.  */
    while (fgets (line, BUFFER_SIZE, stdin)
           && strncmp (&line[10], "coerce", 6) != 0)
      {
        remove_newline (line);
	puts (line);
      }

    puts (line);

    while (fgets (line, BUFFER_SIZE, stdin))
      {
        remove_newline (line);

#ifdef	vax
	if (cp = matchestype() ) {
	    Puts("  register long ");
	    puts(cp);
#else
	if ( matchestype() ) {
	    Puts("  register");
	    puts(line+1);
#endif
	} else
	    puts(line);
    }

    fclose (stdout);
    uexit (0);
}

#else /* not REGFIX */

/* If we don't want to use register variables, we just copy stdin to
   stdout.  If writing or reading fail, exit with bad status.  */

int
main ()
{
  int c;

  while ((c = getchar ()) != EOF)
    {
      if (putchar (c) == EOF)
        {
          perror ("regfix");
          exit (EXIT_FAILURE);
        }
    }

  if (!feof (stdin))
    {
      perror ("regfix");
      exit (EXIT_FAILURE);
    }

  return EXIT_SUCCESS;
}
예제 #21
0
void mainbody( void ) {
    
  initialize () ;
  opengffile () ;
  o = getbyte () ;
  if ( o != 247 ) 
  {
    fprintf ( stderr , "%s%s%c\n",  "Bad GF file: " , "First byte isn't start of preamble!"     , '!' ) ;
    uexit ( 1 ) ;
  } 
  o = getbyte () ;
  if ( o != 131 ) 
  {
    fprintf ( stderr , "%s%s%ld%s%ld%c\n",  "Bad GF file: " , "identification byte should be " ,     (long)131 , " not " , (long)o , '!' ) ;
    uexit ( 1 ) ;
  } 
  o = getbyte () ;
  putc ( '\'' ,  stdout );
  while ( o > 0 ) {
      
    o = o - 1 ;
    putc ( xchr [getbyte () ],  stdout );
  } 
  { putc ( '\'' ,  stdout );  putc ( '\n',  stdout ); }
  do {
      gfprevptr = curloc ;
    do {
	a = curloc ;
      o = getbyte () ;
      p = firstpar ( o ) ;
      if ( eof ( gffile ) ) 
      {
	fprintf ( stderr , "%s%s%c\n",  "Bad GF file: " , "the file ended prematurely" ,         '!' ) ;
	uexit ( 1 ) ;
      } 
      if ( o == 243 ) 
      {
	{
	  if ( wantsmnemonics ) 
	  {
	    putc ('\n',  stdout );
	    fprintf ( stdout , "%ld%s%s%ld%s",  (long)a , ": " , "yyy " , (long)p , " (" ) ;
	  } 
	  if ( wantsmnemonics ) 
	  {
	    printscaled ( p ) ;
	    putc ( ')' ,  stdout );
	  } 
	} 
	o = 244 ;
      } 
      else if ( ( o >= 239 ) && ( o <= 242 ) ) 
      {
	{
	  if ( wantsmnemonics ) 
	  {
	    putc ('\n',  stdout );
	    fprintf ( stdout , "%ld%s%s",  (long)a , ": " , "xxx '" ) ;
	  } 
	  badchar = false ;
	  b = 16 ;
	  if ( p < 0 ) 
	  {
	    putc ('\n',  stdout );
	    fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " , "string of negative length!" ) 
	    ;
	    putc ('\n',  stdout );
	  } 
	  while ( p > 0 ) {
	      
	    q = getbyte () ;
	    if ( ( q < 32 ) || ( q > 126 ) ) 
	    badchar = true ;
	    if ( wantsmnemonics ) 
	    {
	      putc ( xchr [q ],  stdout );
	      if ( b < linelength ) 
	      b = b + 1 ;
	      else {
		  
		putc ('\n',  stdout );
		b = 2 ;
	      } 
	    } 
	    p = p - 1 ;
	  } 
	  if ( wantsmnemonics ) 
	  putc ( '\'' ,  stdout );
	  if ( badchar ) 
	  {
	    putc ('\n',  stdout );
	    fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " ,             "non-ASCII character in xxx command!" ) ;
	    putc ('\n',  stdout );
	  } 
	} 
	o = 244 ;
      } 
      else if ( o == 244 ) {
	  
	if ( wantsmnemonics ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s",  (long)a , ": " , "no op" ) ;
	} 
      } 
    } while ( ! ( o != 244 ) ) ;
    if ( o != 248 ) 
    {
      if ( o != 67 ) {
	  
	if ( o != 68 ) 
	{
	  fprintf ( stderr , "%s%s%ld%s%ld%c%c\n",  "Bad GF file: " , "byte " , (long)curloc - 1 ,           " is not boc (" , (long)o , ')' , '!' ) ;
	  uexit ( 1 ) ;
	} 
      } 
      putc ('\n',  stdout );
      fprintf ( stdout , "%ld%s",  (long)curloc - 1 , ": beginning of char " ) ;
      a = curloc - 1 ;
      totalchars = totalchars + 1 ;
      if ( o == 67 ) 
      {
	charactercode = signedquad () ;
	p = signedquad () ;
	c = charactercode % 256 ;
	if ( c < 0 ) 
	c = c + 256 ;
	minmstated = signedquad () ;
	maxmstated = signedquad () ;
	minnstated = signedquad () ;
	maxnstated = signedquad () ;
      } 
      else {
	  
	charactercode = getbyte () ;
	p = -1 ;
	c = charactercode ;
	q = getbyte () ;
	maxmstated = getbyte () ;
	minmstated = maxmstated - q ;
	q = getbyte () ;
	maxnstated = getbyte () ;
	minnstated = maxnstated - q ;
      } 
      fprintf ( stdout , "%ld",  (long)c ) ;
      if ( charactercode != c ) 
      fprintf ( stdout , "%s%ld",  " with extension " , (long)( charactercode - c ) / 256 ) ;
      if ( wantsmnemonics ) 
      fprintf ( stdout , "%s%ld%s%ld%c%ld%s%ld\n",  ": " , (long)minmstated , "<=m<=" , (long)maxmstated , ' ' ,       (long)minnstated , "<=n<=" , (long)maxnstated ) ;
      maxmobserved = -1 ;
      if ( charptr [c ]!= p ) 
      {
	fprintf ( stdout , "%ld%s%s%s%ld%s%ld%c",  (long)a , ": " , "! " ,         "previous character pointer should be " , (long)charptr [c ], ", not " , (long)p         , '!' ) ;
	putc ('\n',  stdout );
      } 
      else if ( p > 0 ) {
	  
	if ( wantsmnemonics ) 
	fprintf ( stdout , "%s%ld%c\n",          "(previous character with the same code started at byte " , (long)p , ')' ) 
	;
      } 
      charptr [c ]= gfprevptr ;
      if ( wantsmnemonics ) 
      fprintf ( stdout , "%s%ld%c",  "(initially n=" , (long)maxnstated , ')' ) ;
      if ( wantspixels ) 
      {
	maxcol = maxmstated - minmstated - 1 ;
	if ( maxcol > maxcols ) 
	maxcol = maxcols ;
	maxrow = maxnstated - minnstated ;
	if ( maxrow > maxrows ) 
	maxrow = maxrows ;
	if ( ( maxrow >= 0 ) && ( maxcol >= 0 ) ) 
	imagearray = xcallocarray ( pixel , maxcol , maxrow ) ;
      } 
      m = 0 ;
      n = 0 ;
      paintswitch = 0 ;
      if ( ! dochar () ) 
      {
	fprintf ( stderr , "%s%s%c\n",  "Bad GF file: " , "char ended unexpectedly" , '!' ) 
	;
	uexit ( 1 ) ;
      } 
      maxnobserved = n ;
      if ( wantspixels ) 
      {
	if ( ( maxmobserved > maxcol ) || ( maxnobserved > maxrow ) ) 
	fprintf ( stdout , "%s\n",          "(The character is too large to be displayed in full.)" ) ;
	if ( maxcol > maxmobserved ) 
	maxcol = maxmobserved ;
	if ( maxrow > maxnobserved ) 
	maxrow = maxnobserved ;
	if ( maxcol >= 0 ) 
	{
	  fprintf ( stdout , "%s%ld%c%ld%s\n",  ".<--This pixel's lower left corner is at (" ,           (long)minmstated , ',' , (long)maxnstated + 1 , ") in METAFONT coordinates" ) ;
	  n = 0 ;
	  while ( n <= maxrow ) {
	      
	    m = 0 ;
	    b = 0 ;
	    while ( m <= maxcol ) {
		
	      if ( imagearray [m + ( maxcol + 1 ) * n ]== 0 ) 
	      b = b + 1 ;
	      else {
		  
		while ( b > 0 ) {
		    
		  putc ( ' ' ,  stdout );
		  b = b - 1 ;
		} 
		putc ( '*' ,  stdout );
	      } 
	      m = m + 1 ;
	    } 
	    putc ('\n',  stdout );
	    n = n + 1 ;
	  } 
	  fprintf ( stdout , "%s%ld%c%ld%s\n",  ".<--This pixel's upper left corner is at (" ,           (long)minmstated , ',' , (long)maxnstated - maxrow , ") in METAFONT coordinates"           ) ;
	} 
	else
	fprintf ( stdout , "%s\n",  "(The character is entirely blank.)" ) ;
	if ( ( maxrow >= 0 ) && ( maxcol >= 0 ) ) 
	{
	  libcfree ( imagearray ) ;
	  imagearray = nil ;
	} 
      } 
      maxmobserved = minmstated + maxmobserved + 1 ;
      n = maxnstated - maxnobserved ;
      if ( minmstated < minmoverall ) 
      minmoverall = minmstated ;
      if ( maxmobserved > maxmoverall ) 
      maxmoverall = maxmobserved ;
      if ( n < minnoverall ) 
      minnoverall = n ;
      if ( maxnstated > maxnoverall ) 
      maxnoverall = maxnstated ;
      if ( maxmobserved > maxmstated ) 
      fprintf ( stdout , "%s%ld%c\n",  "The previous character should have had max m >= " ,       (long)maxmobserved , '!' ) ;
      if ( n < minnstated ) 
      fprintf ( stdout , "%s%ld%c\n",  "The previous character should have had min n <= " ,       (long)n , '!' ) ;
    } 
  } while ( ! ( o == 248 ) ) ;
  putc ('\n',  stdout );
  readpostamble () ;
  fprintf ( stdout , "%s%ld%s",  "The file had " , (long)totalchars , " character" ) ;
  if ( totalchars != 1 ) 
  putc ( 's' ,  stdout );
  fprintf ( stdout , "%s\n",  " altogether." ) ;
} 
예제 #22
0
integer 
zfirstpar ( eightbits o ) 
{
  register integer Result; switch ( o ) 
  {case 0 : 
  case 1 : 
  case 2 : 
  case 3 : 
  case 4 : 
  case 5 : 
  case 6 : 
  case 7 : 
  case 8 : 
  case 9 : 
  case 10 : 
  case 11 : 
  case 12 : 
  case 13 : 
  case 14 : 
  case 15 : 
  case 16 : 
  case 17 : 
  case 18 : 
  case 19 : 
  case 20 : 
  case 21 : 
  case 22 : 
  case 23 : 
  case 24 : 
  case 25 : 
  case 26 : 
  case 27 : 
  case 28 : 
  case 29 : 
  case 30 : 
  case 31 : 
  case 32 : 
  case 33 : 
  case 34 : 
  case 35 : 
  case 36 : 
  case 37 : 
  case 38 : 
  case 39 : 
  case 40 : 
  case 41 : 
  case 42 : 
  case 43 : 
  case 44 : 
  case 45 : 
  case 46 : 
  case 47 : 
  case 48 : 
  case 49 : 
  case 50 : 
  case 51 : 
  case 52 : 
  case 53 : 
  case 54 : 
  case 55 : 
  case 56 : 
  case 57 : 
  case 58 : 
  case 59 : 
  case 60 : 
  case 61 : 
  case 62 : 
  case 63 : 
    Result = o - 0 ;
    break ;
  case 64 : 
  case 71 : 
  case 245 : 
  case 246 : 
  case 239 : 
    Result = getbyte () ;
    break ;
  case 65 : 
  case 72 : 
  case 240 : 
    Result = gettwobytes () ;
    break ;
  case 66 : 
  case 73 : 
  case 241 : 
    Result = getthreebytes () ;
    break ;
  case 242 : 
  case 243 : 
    Result = signedquad () ;
    break ;
  case 67 : 
  case 68 : 
  case 69 : 
  case 70 : 
  case 244 : 
  case 247 : 
  case 248 : 
  case 249 : 
  case 250 : 
  case 251 : 
  case 252 : 
  case 253 : 
  case 254 : 
  case 255 : 
    Result = 0 ;
    break ;
  case 74 : 
  case 75 : 
  case 76 : 
  case 77 : 
  case 78 : 
  case 79 : 
  case 80 : 
  case 81 : 
  case 82 : 
  case 83 : 
  case 84 : 
  case 85 : 
  case 86 : 
  case 87 : 
  case 88 : 
  case 89 : 
  case 90 : 
  case 91 : 
  case 92 : 
  case 93 : 
  case 94 : 
  case 95 : 
  case 96 : 
  case 97 : 
  case 98 : 
  case 99 : 
  case 100 : 
  case 101 : 
  case 102 : 
  case 103 : 
  case 104 : 
  case 105 : 
  case 106 : 
  case 107 : 
  case 108 : 
  case 109 : 
  case 110 : 
  case 111 : 
  case 112 : 
  case 113 : 
  case 114 : 
  case 115 : 
  case 116 : 
  case 117 : 
  case 118 : 
  case 119 : 
  case 120 : 
  case 121 : 
  case 122 : 
  case 123 : 
  case 124 : 
  case 125 : 
  case 126 : 
  case 127 : 
  case 128 : 
  case 129 : 
  case 130 : 
  case 131 : 
  case 132 : 
  case 133 : 
  case 134 : 
  case 135 : 
  case 136 : 
  case 137 : 
    Result = o - 74 ;
    break ;
  case 138 : 
  case 139 : 
  case 140 : 
  case 141 : 
  case 142 : 
  case 143 : 
  case 144 : 
  case 145 : 
  case 146 : 
  case 147 : 
  case 148 : 
  case 149 : 
  case 150 : 
  case 151 : 
  case 152 : 
  case 153 : 
  case 154 : 
  case 155 : 
  case 156 : 
  case 157 : 
  case 158 : 
  case 159 : 
  case 160 : 
  case 161 : 
  case 162 : 
  case 163 : 
  case 164 : 
  case 165 : 
  case 166 : 
  case 167 : 
  case 168 : 
  case 169 : 
  case 170 : 
  case 171 : 
  case 172 : 
  case 173 : 
  case 174 : 
  case 175 : 
  case 176 : 
  case 177 : 
  case 178 : 
  case 179 : 
  case 180 : 
  case 181 : 
  case 182 : 
  case 183 : 
  case 184 : 
  case 185 : 
  case 186 : 
  case 187 : 
  case 188 : 
  case 189 : 
  case 190 : 
  case 191 : 
  case 192 : 
  case 193 : 
  case 194 : 
  case 195 : 
  case 196 : 
  case 197 : 
  case 198 : 
  case 199 : 
  case 200 : 
  case 201 : 
    Result = o - 74 ;
    break ;
  case 202 : 
  case 203 : 
  case 204 : 
  case 205 : 
  case 206 : 
  case 207 : 
  case 208 : 
  case 209 : 
  case 210 : 
  case 211 : 
  case 212 : 
  case 213 : 
  case 214 : 
  case 215 : 
  case 216 : 
  case 217 : 
  case 218 : 
  case 219 : 
  case 220 : 
  case 221 : 
  case 222 : 
  case 223 : 
  case 224 : 
  case 225 : 
  case 226 : 
  case 227 : 
  case 228 : 
  case 229 : 
  case 230 : 
  case 231 : 
  case 232 : 
  case 233 : 
  case 234 : 
  case 235 : 
  case 236 : 
  case 237 : 
  case 238 : 
    Result = o - 74 ;
    break ;
    default: 
    {
      fprintf ( stderr , "%s\n",  "internal error" ) ;
      uexit ( 1 ) ;
    } 
    break ;
  } 
  return Result ;
} 
예제 #23
0
void mainbody( void ) {
    
  initialize () ;
  if ( ! organize () ) 
  uexit ( 1 ) ;
  dosimplethings () ;
  if ( nl > 0 ) 
  {
    {register integer for_end; ai = 0 ;for_end = nl - 1 ; if ( ai <= 
    for_end) do 
      activity [ai ]= 0 ;
    while ( ai++ < for_end ) ;} 
    if ( tfm [4 * ( ligkernbase + ( 0 ) ) ]== 255 ) 
    {
      left () ;
      Fputs ( plfile ,  "BOUNDARYCHAR" ) ;
      boundarychar = tfm [4 * ( ligkernbase + ( 0 ) ) + 1 ];
      outchar ( boundarychar ) ;
      right () ;
      activity [0 ]= 1 ;
    } 
    if ( tfm [4 * ( ligkernbase + ( nl - 1 ) ) ]== 255 ) 
    {
      r = 256 * tfm [4 * ( ligkernbase + ( nl - 1 ) ) + 2 ]+ tfm [4 * ( 
      ligkernbase + ( nl - 1 ) ) + 3 ];
      if ( r >= nl ) 
      {
	perfect = false ;
	{ putc ( ' ' ,  stderr );  putc ( '\n',  stderr ); }
	Fputs ( stderr ,          "Ligature/kern starting index for boundarychar is too large;" ) ;
	fprintf ( stderr , "%s\n",  "so I removed it." ) ;
      } 
      else {
	  
	labelptr = 1 ;
	labeltable [1 ].cc = 256 ;
	labeltable [1 ].rr = r ;
	bcharlabel = r ;
	activity [r ]= 2 ;
      } 
      activity [nl - 1 ]= 1 ;
    } 
  } 
  {register integer for_end; c = bc ;for_end = ec ; if ( c <= for_end) do 
    if ( ( tfm [4 * ( charbase + c ) + 2 ]% 4 ) == 1 ) 
    {
      r = tfm [4 * ( charbase + c ) + 3 ];
      if ( r < nl ) 
      {
	if ( tfm [4 * ( ligkernbase + ( r ) ) ]> 128 ) 
	{
	  r = 256 * tfm [4 * ( ligkernbase + ( r ) ) + 2 ]+ tfm [4 * ( 
	  ligkernbase + ( r ) ) + 3 ];
	  if ( r < nl ) {
	      
	    if ( activity [tfm [4 * ( charbase + c ) + 3 ]]== 0 ) 
	    activity [tfm [4 * ( charbase + c ) + 3 ]]= 1 ;
	  } 
	} 
      } 
      if ( r >= nl ) 
      {
	perfect = false ;
	{ putc ( ' ' ,  stderr );  putc ( '\n',  stderr ); }
	Fputs ( stderr ,  "Ligature/kern starting index for character " ) ;
	printoctal ( c ) ;
	fprintf ( stderr , "%s\n",  " is too large;" ) ;
	fprintf ( stderr , "%s\n",  "so I removed it." ) ;
	tfm [4 * ( charbase + c ) + 2 ]= 4 * ( tfm [4 * ( charbase + c ) + 
	2 ]/ 4 ) + 0 ;
      } 
      else {
	  
	sortptr = labelptr ;
	while ( labeltable [sortptr ].rr > r ) {
	    
	  labeltable [sortptr + 1 ]= labeltable [sortptr ];
	  sortptr = sortptr - 1 ;
	} 
	labeltable [sortptr + 1 ].cc = c ;
	labeltable [sortptr + 1 ].rr = r ;
	labelptr = labelptr + 1 ;
	activity [r ]= 2 ;
      } 
    } 
  while ( c++ < for_end ) ;} 
  labeltable [labelptr + 1 ].rr = ligsize ;
  if ( nl > 0 ) 
  {
    left () ;
    Fputs ( plfile ,  "LIGTABLE" ) ;
    outln () ;
    {register integer for_end; ai = 0 ;for_end = nl - 1 ; if ( ai <= 
    for_end) do 
      if ( activity [ai ]== 2 ) 
      {
	r = tfm [4 * ( ligkernbase + ( ai ) ) ];
	if ( r < 128 ) 
	{
	  r = r + ai + 1 ;
	  if ( r >= nl ) 
	  {
	    {
	      perfect = false ;
	      if ( charsonline > 0 ) 
	      { putc ( ' ' ,  stderr );  putc ( '\n',  stderr ); }
	      charsonline = 0 ;
	      fprintf ( stderr , "%s%s%ld%s\n",  "Bad TFM file: " , "Ligature/kern step " , (long)ai               , " skips too far;" ) ;
	    } 
	    fprintf ( stderr , "%s\n",  "I made it stop." ) ;
	    tfm [4 * ( ligkernbase + ( ai ) ) ]= 128 ;
	  } 
	  else activity [r ]= 2 ;
	} 
      } 
    while ( ai++ < for_end ) ;} 
    sortptr = 1 ;
    {register integer for_end; acti = 0 ;for_end = nl - 1 ; if ( acti <= 
    for_end) do 
      if ( activity [acti ]!= 1 ) 
      {
	i = acti ;
	if ( activity [i ]== 0 ) 
	{
	  if ( level == 1 ) 
	  {
	    left () ;
	    Fputs ( plfile ,  "COMMENT THIS PART OF THE PROGRAM IS NEVER USED!"             ) ;
	    outln () ;
	  } 
	} 
	else if ( level == 2 ) 
	right () ;
	while ( i == labeltable [sortptr ].rr ) {
	    
	  left () ;
	  Fputs ( plfile ,  "LABEL" ) ;
	  if ( labeltable [sortptr ].cc == 256 ) 
	  Fputs ( plfile ,  " BOUNDARYCHAR" ) ;
	  else outchar ( labeltable [sortptr ].cc ) ;
	  right () ;
	  sortptr = sortptr + 1 ;
	} 
	{
	  k = 4 * ( ligkernbase + ( i ) ) ;
	  if ( tfm [k ]> 128 ) 
	  {
	    if ( 256 * tfm [k + 2 ]+ tfm [k + 3 ]>= nl ) 
	    {
	      perfect = false ;
	      if ( charsonline > 0 ) 
	      { putc ( ' ' ,  stderr );  putc ( '\n',  stderr ); }
	      charsonline = 0 ;
	      fprintf ( stderr , "%s%s\n",  "Bad TFM file: " ,               "Ligature unconditional stop command address is too big." ) ;
	    } 
	  } 
	  else if ( tfm [k + 2 ]>= 128 ) 
	  {
	    if ( ( ( tfm [k + 1 ]< bc ) || ( tfm [k + 1 ]> ec ) || ( tfm [
	    4 * ( charbase + tfm [k + 1 ]) ]== 0 ) ) ) {
		
	      if ( tfm [k + 1 ]!= boundarychar ) 
	      {
		perfect = false ;
		if ( charsonline > 0 ) 
		{ putc ( ' ' ,  stderr );  putc ( '\n',  stderr ); }
		charsonline = 0 ;
		fprintf ( stderr , "%s%s%s",  "Bad TFM file: " , "Kern step for" ,                 " nonexistent character " ) ;
		printoctal ( tfm [k + 1 ]) ;
		{ putc ( '.' ,  stderr );  putc ( '\n',  stderr ); }
		tfm [k + 1 ]= bc ;
	      } 
	    } 
	    left () ;
	    Fputs ( plfile ,  "KRN" ) ;
	    outchar ( tfm [k + 1 ]) ;
	    r = 256 * ( tfm [k + 2 ]- 128 ) + tfm [k + 3 ];
	    if ( r >= nk ) 
	    {
	      {
		perfect = false ;
		if ( charsonline > 0 ) 
		{ putc ( ' ' ,  stderr );  putc ( '\n',  stderr ); }
		charsonline = 0 ;
		fprintf ( stderr , "%s%s\n",  "Bad TFM file: " , "Kern index too large."                 ) ;
	      } 
	      Fputs ( plfile ,  " R 0.0" ) ;
	    } 
	    else outfix ( 4 * ( kernbase + r ) ) ;
	    right () ;
	  } 
	  else {
	      
	    if ( ( ( tfm [k + 1 ]< bc ) || ( tfm [k + 1 ]> ec ) || ( tfm [
	    4 * ( charbase + tfm [k + 1 ]) ]== 0 ) ) ) {
		
	      if ( tfm [k + 1 ]!= boundarychar ) 
	      {
		perfect = false ;
		if ( charsonline > 0 ) 
		{ putc ( ' ' ,  stderr );  putc ( '\n',  stderr ); }
		charsonline = 0 ;
		fprintf ( stderr , "%s%s%s",  "Bad TFM file: " , "Ligature step for" ,                 " nonexistent character " ) ;
		printoctal ( tfm [k + 1 ]) ;
		{ putc ( '.' ,  stderr );  putc ( '\n',  stderr ); }
		tfm [k + 1 ]= bc ;
	      } 
	    } 
	    if ( ( ( tfm [k + 3 ]< bc ) || ( tfm [k + 3 ]> ec ) || ( tfm [
	    4 * ( charbase + tfm [k + 3 ]) ]== 0 ) ) ) 
	    {
	      perfect = false ;
	      if ( charsonline > 0 ) 
	      { putc ( ' ' ,  stderr );  putc ( '\n',  stderr ); }
	      charsonline = 0 ;
	      fprintf ( stderr , "%s%s%s",  "Bad TFM file: " , "Ligature step produces the"               , " nonexistent character " ) ;
	      printoctal ( tfm [k + 3 ]) ;
	      { putc ( '.' ,  stderr );  putc ( '\n',  stderr ); }
	      tfm [k + 3 ]= bc ;
	    } 
	    left () ;
	    r = tfm [k + 2 ];
	    if ( ( r == 4 ) || ( ( r > 7 ) && ( r != 11 ) ) ) 
	    {
	      fprintf ( stderr , "%s\n",                "Ligature step with nonstandard code changed to LIG" ) ;
	      r = 0 ;
	      tfm [k + 2 ]= 0 ;
	    } 
	    if ( r % 4 > 1 ) 
	    putc ( '/' ,  plfile );
	    Fputs ( plfile ,  "LIG" ) ;
	    if ( odd ( r ) ) 
	    putc ( '/' ,  plfile );
	    while ( r > 3 ) {
		
	      putc ( '>' ,  plfile );
	      r = r - 4 ;
	    } 
	    outchar ( tfm [k + 1 ]) ;
	    outchar ( tfm [k + 3 ]) ;
	    right () ;
	  } 
	  if ( tfm [k ]> 0 ) {
	      
	    if ( level == 1 ) 
	    {
	      if ( tfm [k ]>= 128 ) 
	      Fputs ( plfile ,  "(STOP)" ) ;
	      else {
		  
		count = 0 ;
		{register integer for_end; ai = i + 1 ;for_end = i + tfm [k 
		]; if ( ai <= for_end) do 
		  if ( activity [ai ]== 2 ) 
		  count = count + 1 ;
		while ( ai++ < for_end ) ;} 
		fprintf ( plfile , "%s%ld%c",  "(SKIP D " , (long)count , ')' ) ;
	      } 
	      outln () ;
	    } 
	  } 
	} 
      } 
    while ( acti++ < for_end ) ;} 
    if ( level == 2 ) 
    right () ;
    right () ;
    hashptr = 0 ;
    yligcycle = 256 ;
    {register integer for_end; hh = 0 ;for_end = hashsize ; if ( hh <= 
    for_end) do 
      hash [hh ]= 0 ;
    while ( hh++ < for_end ) ;} 
    {register integer for_end; c = bc ;for_end = ec ; if ( c <= for_end) do 
      if ( ( tfm [4 * ( charbase + c ) + 2 ]% 4 ) == 1 ) 
      {
	i = tfm [4 * ( charbase + c ) + 3 ];
	if ( tfm [4 * ( ligkernbase + ( i ) ) ]> 128 ) 
	i = 256 * tfm [4 * ( ligkernbase + ( i ) ) + 2 ]+ tfm [4 * ( 
	ligkernbase + ( i ) ) + 3 ];
	do {
	    hashinput () ;
	  k = tfm [4 * ( ligkernbase + ( i ) ) ];
	  if ( k >= 128 ) 
	  i = nl ;
	  else i = i + 1 + k ;
	} while ( ! ( i >= nl ) ) ;
      } 
    while ( c++ < for_end ) ;} 
    if ( bcharlabel < nl ) 
    {
      c = 256 ;
      i = bcharlabel ;
      do {
	  hashinput () ;
	k = tfm [4 * ( ligkernbase + ( i ) ) ];
	if ( k >= 128 ) 
	i = nl ;
	else i = i + 1 + k ;
      } while ( ! ( i >= nl ) ) ;
    } 
    if ( hashptr == hashsize ) 
    {
      fprintf ( stderr , "%s\n",        "Sorry, I haven't room for so many ligature/kern pairs!" ) ;
      uexit ( 1 ) ;
    } 
    {register integer for_end; hh = 1 ;for_end = hashptr ; if ( hh <= 
    for_end) do 
      {
	r = hashlist [hh ];
	if ( classvar [r ]> 0 ) 
	r = ffn ( r , ( hash [r ]- 1 ) / 256 , ( hash [r ]- 1 ) % 256 ) ;
      } 
    while ( hh++ < for_end ) ;} 
    if ( yligcycle < 256 ) 
    {
      Fputs ( stderr ,  "Infinite ligature loop starting with " ) ;
      if ( xligcycle == 256 ) 
      Fputs ( stderr ,  "boundary" ) ;
      else printoctal ( xligcycle ) ;
      Fputs ( stderr ,  " and " ) ;
      printoctal ( yligcycle ) ;
      { putc ( '!' ,  stderr );  putc ( '\n',  stderr ); }
      Fputs ( plfile ,  "(INFINITE LIGATURE LOOP MUST BE BROKEN!)" ) ;
      uexit ( 1 ) ;
    } 
  } 
  if ( ne > 0 ) 
  {register integer for_end; c = 0 ;for_end = ne - 1 ; if ( c <= for_end) do 
    {register integer for_end; d = 0 ;for_end = 3 ; if ( d <= for_end) do 
      {
	k = 4 * ( extenbase + c ) + d ;
	if ( ( tfm [k ]> 0 ) || ( d == 3 ) ) 
	{
	  if ( ( ( tfm [k ]< bc ) || ( tfm [k ]> ec ) || ( tfm [4 * ( 
	  charbase + tfm [k ]) ]== 0 ) ) ) 
	  {
	    {
	      perfect = false ;
	      if ( charsonline > 0 ) 
	      { putc ( ' ' ,  stderr );  putc ( '\n',  stderr ); }
	      charsonline = 0 ;
	      fprintf ( stderr , "%s%s%s",  "Bad TFM file: " ,               "Extensible recipe involves the" , " nonexistent character " ) ;
	      printoctal ( tfm [k ]) ;
	      { putc ( '.' ,  stderr );  putc ( '\n',  stderr ); }
	    } 
	    if ( d < 3 ) 
	    tfm [k ]= 0 ;
	  } 
	} 
      } 
    while ( d++ < for_end ) ;} 
  while ( c++ < for_end ) ;} 
  docharacters () ;
  if ( verbose ) 
  { putc ( '.' ,  stderr );  putc ( '\n',  stderr ); }
  if ( level != 0 ) 
  fprintf ( stderr , "%s\n",  "This program isn't working!" ) ;
  if ( ! perfect ) 
  {
    Fputs ( plfile ,      "(COMMENT THE TFM FILE WAS BAD, SO THE DATA HAS BEEN CHANGED!)" ) ;
    putc ('\n',  plfile );
  } 
} 
예제 #24
0
boolean 
dochar ( void ) 
{
  /* 9998 9999 */ register boolean Result; eightbits o  ;
  integer p, q  ;
  boolean aok  ;
  aok = true ;
  while ( true ) {
      
    a = curloc ;
    o = getbyte () ;
    p = firstpar ( o ) ;
    if ( eof ( gffile ) ) 
    {
      fprintf ( stderr , "%s%s%c\n",  "Bad GF file: " , "the file ended prematurely" , '!'       ) ;
      uexit ( 1 ) ;
    } 
    if ( o <= 67 ) 
    {
      if ( wantsmnemonics ) 
      Fputs ( stdout ,  " paint " ) ;
      do {
	  if ( wantsmnemonics ) { 
	  if ( paintswitch == 0 ) 
	  fprintf ( stdout , "%c%ld%c",  '(' , (long)p , ')' ) ;
	  else
	  fprintf ( stdout , "%ld",  (long)p ) ;
	} 
	m = m + p ;
	if ( m > maxmobserved ) 
	maxmobserved = m - 1 ;
	if ( wantspixels ) {
	    
	  if ( paintswitch == 1 ) {
	      
	    if ( n <= maxrow ) 
	    {
	      l = m - p ;
	      r = m - 1 ;
	      if ( r > maxcol ) 
	      r = maxcol ;
	      m = l ;
	      while ( m <= r ) {
		  
		imagearray [m + ( maxcol + 1 ) * n ]= 1 ;
		m = m + 1 ;
	      } 
	      m = l + p ;
	    } 
	  } 
	} 
	paintswitch = 1 - paintswitch ;
	a = curloc ;
	o = getbyte () ;
	p = firstpar ( o ) ;
	if ( eof ( gffile ) ) 
	{
	  fprintf ( stderr , "%s%s%c\n",  "Bad GF file: " , "the file ended prematurely" ,           '!' ) ;
	  uexit ( 1 ) ;
	} 
      } while ( ! ( o > 67 ) ) ;
    } 
    switch ( o ) 
    {case 70 : 
    case 71 : 
    case 72 : 
    case 73 : 
      {
	if ( wantsmnemonics ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s%ld%c%ld",  (long)a , ": " , "skip" , (long)( o - 70 ) % 4 , ' ' , (long)p ) ;
	} 
	n = n + p + 1 ;
	m = 0 ;
	paintswitch = 0 ;
	if ( wantsmnemonics ) 
	fprintf ( stdout , "%s%ld%c",  " (n=" , (long)maxnstated - n , ')' ) ;
      } 
      break ;
    case 74 : 
    case 75 : 
    case 76 : 
    case 77 : 
    case 78 : 
    case 79 : 
    case 80 : 
    case 81 : 
    case 82 : 
    case 83 : 
    case 84 : 
    case 85 : 
    case 86 : 
    case 87 : 
    case 88 : 
    case 89 : 
    case 90 : 
    case 91 : 
    case 92 : 
    case 93 : 
    case 94 : 
    case 95 : 
    case 96 : 
    case 97 : 
    case 98 : 
    case 99 : 
    case 100 : 
    case 101 : 
    case 102 : 
    case 103 : 
    case 104 : 
    case 105 : 
    case 106 : 
    case 107 : 
    case 108 : 
    case 109 : 
    case 110 : 
    case 111 : 
    case 112 : 
    case 113 : 
    case 114 : 
    case 115 : 
    case 116 : 
    case 117 : 
    case 118 : 
    case 119 : 
    case 120 : 
    case 121 : 
    case 122 : 
    case 123 : 
    case 124 : 
    case 125 : 
    case 126 : 
    case 127 : 
    case 128 : 
    case 129 : 
    case 130 : 
    case 131 : 
    case 132 : 
    case 133 : 
    case 134 : 
    case 135 : 
    case 136 : 
    case 137 : 
      {
	if ( wantsmnemonics ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s%ld",  (long)a , ": " , "newrow " , (long)p ) ;
	} 
	n = n + 1 ;
	m = p ;
	paintswitch = 1 ;
	if ( wantsmnemonics ) 
	fprintf ( stdout , "%s%ld%c",  " (n=" , (long)maxnstated - n , ')' ) ;
      } 
      break ;
    case 138 : 
    case 139 : 
    case 140 : 
    case 141 : 
    case 142 : 
    case 143 : 
    case 144 : 
    case 145 : 
    case 146 : 
    case 147 : 
    case 148 : 
    case 149 : 
    case 150 : 
    case 151 : 
    case 152 : 
    case 153 : 
    case 154 : 
    case 155 : 
    case 156 : 
    case 157 : 
    case 158 : 
    case 159 : 
    case 160 : 
    case 161 : 
    case 162 : 
    case 163 : 
    case 164 : 
    case 165 : 
    case 166 : 
    case 167 : 
    case 168 : 
    case 169 : 
    case 170 : 
    case 171 : 
    case 172 : 
    case 173 : 
    case 174 : 
    case 175 : 
    case 176 : 
    case 177 : 
    case 178 : 
    case 179 : 
    case 180 : 
    case 181 : 
    case 182 : 
    case 183 : 
    case 184 : 
    case 185 : 
    case 186 : 
    case 187 : 
    case 188 : 
    case 189 : 
    case 190 : 
    case 191 : 
    case 192 : 
    case 193 : 
    case 194 : 
    case 195 : 
    case 196 : 
    case 197 : 
    case 198 : 
    case 199 : 
    case 200 : 
    case 201 : 
      {
	if ( wantsmnemonics ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s%ld",  (long)a , ": " , "newrow " , (long)p ) ;
	} 
	n = n + 1 ;
	m = p ;
	paintswitch = 1 ;
	if ( wantsmnemonics ) 
	fprintf ( stdout , "%s%ld%c",  " (n=" , (long)maxnstated - n , ')' ) ;
      } 
      break ;
    case 202 : 
    case 203 : 
    case 204 : 
    case 205 : 
    case 206 : 
    case 207 : 
    case 208 : 
    case 209 : 
    case 210 : 
    case 211 : 
    case 212 : 
    case 213 : 
    case 214 : 
    case 215 : 
    case 216 : 
    case 217 : 
    case 218 : 
    case 219 : 
    case 220 : 
    case 221 : 
    case 222 : 
    case 223 : 
    case 224 : 
    case 225 : 
    case 226 : 
    case 227 : 
    case 228 : 
    case 229 : 
    case 230 : 
    case 231 : 
    case 232 : 
    case 233 : 
    case 234 : 
    case 235 : 
    case 236 : 
    case 237 : 
    case 238 : 
      {
	if ( wantsmnemonics ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s%ld",  (long)a , ": " , "newrow " , (long)p ) ;
	} 
	n = n + 1 ;
	m = p ;
	paintswitch = 1 ;
	if ( wantsmnemonics ) 
	fprintf ( stdout , "%s%ld%c",  " (n=" , (long)maxnstated - n , ')' ) ;
      } 
      break ;
    case 244 : 
      if ( wantsmnemonics ) 
      {
	putc ('\n',  stdout );
	fprintf ( stdout , "%ld%s%s",  (long)a , ": " , "no op" ) ;
      } 
      break ;
    case 247 : 
      {
	{
	  fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " ,           "preamble command within a character!" ) ;
	  putc ('\n',  stdout );
	} 
	goto lab9998 ;
      } 
      break ;
    case 248 : 
    case 249 : 
      {
	{
	  fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " ,           "postamble command within a character!" ) ;
	  putc ('\n',  stdout );
	} 
	goto lab9998 ;
      } 
      break ;
    case 67 : 
    case 68 : 
      {
	{
	  fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " , "boc occurred before eoc!" ) ;
	  putc ('\n',  stdout );
	} 
	goto lab9998 ;
      } 
      break ;
    case 69 : 
      {
	if ( wantsmnemonics ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s",  (long)a , ": " , "eoc" ) ;
	} 
	putc ('\n',  stdout );
	goto lab9999 ;
      } 
      break ;
    case 239 : 
    case 240 : 
    case 241 : 
    case 242 : 
      {
	if ( wantsmnemonics ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s",  (long)a , ": " , "xxx '" ) ;
	} 
	badchar = false ;
	b = 16 ;
	if ( p < 0 ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " , "string of negative length!" ) ;
	  putc ('\n',  stdout );
	} 
	while ( p > 0 ) {
	    
	  q = getbyte () ;
	  if ( ( q < 32 ) || ( q > 126 ) ) 
	  badchar = true ;
	  if ( wantsmnemonics ) 
	  {
	    putc ( xchr [q ],  stdout );
	    if ( b < linelength ) 
	    b = b + 1 ;
	    else {
		
	      putc ('\n',  stdout );
	      b = 2 ;
	    } 
	  } 
	  p = p - 1 ;
	} 
	if ( wantsmnemonics ) 
	putc ( '\'' ,  stdout );
	if ( badchar ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s%s",  (long)a , ": " , "! " ,           "non-ASCII character in xxx command!" ) ;
	  putc ('\n',  stdout );
	} 
      } 
      break ;
    case 243 : 
      {
	if ( wantsmnemonics ) 
	{
	  putc ('\n',  stdout );
	  fprintf ( stdout , "%ld%s%s%ld%s",  (long)a , ": " , "yyy " , (long)p , " (" ) ;
	} 
	if ( wantsmnemonics ) 
	{
	  printscaled ( p ) ;
	  putc ( ')' ,  stdout );
	} 
      } 
      break ;
      default: 
      {
	fprintf ( stdout , "%ld%s%s%s%ld%c",  (long)a , ": " , "! " , "undefined command " , (long)o , '!' ) ;
	putc ('\n',  stdout );
      } 
      break ;
    } 
  } 
  lab9998: { putc ( '!' ,  stdout );  putc ( '\n',  stdout ); }
  aok = false ;
  lab9999: Result = aok ;
  return Result ;
} 
예제 #25
0
파일: luatex.c 프로젝트: live-clones/luatex
boolean input_line(FILE * f)
{
    int i = EOF;

#ifdef WIN32
    if (f != Poptr && fileno (f) != fileno (stdin)) {
        long position = ftell (f);
        if (position == 0L) {
            /* Detect and skip Byte order marks.  */
            int k1 = getc (f);

            if (k1 != 0xff && k1 != 0xfe && k1 != 0xef)
                rewind (f);
            else {
                int k2 = getc (f);
                if (k2 != 0xff && k2 != 0xfe && k2 != 0xbb)
                    rewind (f);
                else if ((k1 == 0xff && k2 == 0xfe) || /* UTF-16(LE) */
                         (k1 == 0xfe && k2 == 0xff))   /* UTF-16(BE) */
                    ;
                else {
                    int k3 = getc (f);
                    int k4 = getc (f);
                    if (k1 == 0xef && k2 == 0xbb && k3 == 0xbf &&
                        k4 >= 0 && k4 <= 0x7e) /* UTF-8 */
                        ungetc (k4, f);
                    else
                        rewind (f);
                }
            }
        }
    }
#endif
    /*
        Recognize either LF or CR as a line terminator.
    */
    last = first;
    while (last < buf_size && (i = getc(f)) != EOF && i != '\n' && i != '\r')
        buffer[last++] = (packed_ASCII_code) i;

    if (i == EOF && errno != EINTR && last == first)
        return false;

    /*
        We didn't get the whole line because our buffer was too small.
    */
    if (i != EOF && i != '\n' && i != '\r') {
        fprintf(stderr, "! Unable to read an entire line---bufsize=%u.\n",
                (unsigned) buf_size);
        fputs("Please increase buf_size in texmf.cnf.\n", stderr);
        uexit(1);
    }

    buffer[last] = ' ';
    if (last >= max_buf_stack)
        max_buf_stack = last;

    /*
        If next char is LF of a CRLF, read it.
    */
    if (i == '\r') {
        while ((i = getc(f)) == EOF && errno == EINTR);
        if (i != '\n')
            ungetc(i, f);
    }

    /*
        Trim trailing space character (but not, e.g., tabs). We can't have line
        terminators because we stopped reading at the first \r or \n. TeX's rule
        is to strip only trailing spaces (and eols). David Fuchs mentions that
        this stripping was done to ensure portability of TeX documents given the
        padding with spaces on fixed-record "lines" on some systems of the time,
        e.g., IBM VM/CMS and OS/360.
    */
    while (last > first && buffer[last - 1] == ' ')
        --last;

    /*
        Don't bother using xord if we don't need to.
    */

    return true;
}
예제 #26
0
boolean input_line(FILE * f)
{
    int i = EOF;

#ifdef WIN32
    if (f != Poptr && fileno (f) != fileno (stdin)) {
        long position = ftell (f);

        if (position == 0L) {  /* Detect and skip Byte order marks.  */
            int k1 = getc (f);

            if (k1 != 0xff && k1 != 0xfe && k1 != 0xef)
                rewind (f);
            else {
                int k2 = getc (f);

                if (k2 != 0xff && k2 != 0xfe && k2 != 0xbb)
                    rewind (f);
                else if ((k1 == 0xff && k2 == 0xfe) || /* UTF-16(LE) */
                         (k1 == 0xfe && k2 == 0xff))   /* UTF-16(BE) */
                    ;
                else {
                    int k3 = getc (f);

                    if (k1 == 0xef && k2 == 0xbb && k3 == 0xbf) /* UTF-8 */
                        ;
                    else
                        rewind (f);
                }
            }
        }
    }
#endif
    /* Recognize either LF or CR as a line terminator.  */
    last = first;
    while (last < buf_size && (i = getc(f)) != EOF && i != '\n' && i != '\r')
        buffer[last++] = (packed_ASCII_code) i;

    if (i == EOF && errno != EINTR && last == first)
        return false;

    /* We didn't get the whole line because our buffer was too small.  */
    if (i != EOF && i != '\n' && i != '\r') {
        fprintf(stderr, "! Unable to read an entire line---bufsize=%u.\n",
                (unsigned) buf_size);
        fputs("Please increase buf_size in texmf.cnf.\n", stderr);
        uexit(1);
    }

    buffer[last] = ' ';
    if (last >= max_buf_stack)
        max_buf_stack = last;

    /* If next char is LF of a CRLF, read it.  */
    if (i == '\r') {
        while ((i = getc(f)) == EOF && errno == EINTR);
        if (i != '\n')
            ungetc(i, f);
    }

    /* Trim trailing whitespace.  */
    while (last > first && ISBLANK(buffer[last - 1]))
        --last;

    /* Don't bother using xord if we don't need to.  */

    return true;
}