MDOS3: list bootconf

Ostatné témy, ktoré nepasujú vyššie
Post Reply
Message
Author
ub880d
Posts: 24
Joined: Sun Oct 06, 2013 11:19 pm

MDOS3: list bootconf

#1 Post by ub880d » Tue May 13, 2014 12:22 am

ak by sa niekomu hodilo, mala utilitka na vypis obsahu bootconf.b z bootdisku pre mdos3

Code: Select all

/* 
 * Copyright (C) 2014 UB880D
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. See the file COPYING. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

/*

 print list of systems from bootconf file (mdos3)

*/

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define TITLELEN 32
#define FNAMELEN 10

int main(int argc, char *argv[]) {
  int fd, len, sysnr;
  
  char title[TITLELEN+1];
  unsigned char page;
  char file[FNAMELEN+1];
  
  if (argc < 2) {
    printf("Usage: %s <file>\n", argv[0]);
    return 1;
  }
  
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    printf("cannot open %s file\n", argv[1]);
    return 1;
  }
  
  sysnr = 0;

  while ((len = read(fd, title, TITLELEN)) > 0) {

    if (!*title) break;
    
    if (len != TITLELEN) {
      len = 0; //to print warning
      break;
    }
    
    title[TITLELEN] = '\0';
    
    printf("[%d] System: %s\n", sysnr, title);
    
    if ((len = read(fd, &page, 1)) < 1) break;
    
    while (!(page&0x80)) {
      
      if ((len = read(fd, file, FNAMELEN)) < FNAMELEN) {
        len = 0; //to print warning
        break;
      }
      
      file[FNAMELEN] = '\0';
      
      printf("  Page %d: %s\n", (page & 0x3), file);
      if ((len = read(fd, &page, 1)) < 1) break;
    }
    
    if (page == 0xff)
      printf("  8k paging, initial page is 0 (legacy)\n\n");
    else {
      if ((page & 0x40))
        printf("  16k paging, initial 16k page is %d\n\n", (page & 0x1));
      else
        printf("  8k paging, initial page is %d\n\n", (page & 0x3));
    }
    
    sysnr++;
    
  }
  
  if (!len) printf("WARNING! premature end of file!\n");
  
  close(fd);

  return 0;
}

Post Reply