1 /* $Id: list.c,v 1.9 1994/06/24 11:00:15 ceriel Exp $ */
12 static line_positions();
16 extern t_lineno currline;
17 extern int interrupted;
20 mk_filnm(dir, file, newname)
25 register char *dst = Malloc((unsigned) (strlen(dir) + strlen(file) + 2));
29 while (*dst++ = *dir++) /* nothing */;
32 while (*dst++ = *file++) /* nothing */;
36 open_file(fn, mode, ffn)
46 return fopen(fn, mode);
50 mk_filnm(*p++, fn, ffn);
51 if ((f = fopen(*ffn, mode)) != NULL) {
63 static p_file last_file;
68 if (last_file != file) {
69 if (last_f) fclose(last_f);
71 if (!(f = open_file(file->f_sym->sy_idf->id_text,
73 &file->f_fullname))) {
74 error("could not open %s", file->f_sym->sy_idf->id_text);
79 if (! file->f_linepos) {
80 line_positions(file, f);
86 if (l1 > file->f_nlines) l1 = file->f_nlines;
87 if (l1+l2-1 > file->f_nlines) l2 = file->f_nlines - l1 + 1;
89 fseek(f, *(file->f_linepos+(l1-1)), 0);
90 for (n = l1; n < l1 + l2; n++) {
93 if (interrupted) return;
94 fprintf(db_out, "%c%5d\t", currfile && file == currfile->sy_file && n == currline ? '>' : ' ', n);
97 if (c != EOF) putc(c, db_out);
98 } while (c != '\n' && c != EOF);
105 line_positions(file, f)
110 unsigned int n_alloc = 256;
111 register long cnt = 0;
114 file->f_linepos = (long *) Malloc(n_alloc * sizeof(long));
115 file->f_linepos[0] = 0;
117 while ((c = getc(f)) != EOF) {
123 (long *) Realloc((char *)(file->f_linepos),
124 n_alloc * sizeof(long));
126 file->f_linepos[nl++] = cnt;
129 if (cnt == file->f_linepos[nl-1]) nl--;
130 file->f_linepos = (long *) Realloc((char *)(file->f_linepos),
131 (unsigned)nl * sizeof(long));