home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / printer / dotab10.arc / DOTAB.C next >
Text File  |  1987-03-03  |  3KB  |  113 lines

  1. #define lint_args
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. /************************************************************/
  6. FILE  *infile, *outfile;
  7. char  **args, *outname, outspec[64];
  8. int   argnum, nspaces = 5;
  9. /************************************************************/
  10. /*global*/  void getparms(void);
  11. /*global*/  void make_outname(void);
  12. /*global*/  void get_nspaces(void);
  13. /*global*/  void openfiles(void);
  14. /*global*/  void dotabs(void);
  15. /************************************************************/
  16. main (argc,argv)    /* DOTAB  srcefile nspaces [outfile]   */
  17. char  *argv[];
  18. {
  19. args = argv;
  20. argnum = argc;
  21. getparms ();
  22. openfiles ();
  23. dotabs ();
  24.  
  25. if (fcloseall() != 2) {
  26.   fprintf (stderr,
  27.     "error occurred when closing files");
  28.   exit (1);
  29.   }
  30. exit (0);
  31. }
  32. /************************************************************/
  33. /************************************************************/
  34. void getparms () {
  35.  
  36. switch (argnum) {
  37.  
  38.   case 1 :  /* nothing entered */
  39.     fprintf (stderr, \
  40.       "DOTAB sourcefile nspaces outfile  \n");
  41.       exit (1);
  42.  
  43.   case 2 :  /* outfile and nspaces not entered */
  44.     make_outname ();
  45.     break;
  46.  
  47.   case 3 :  /* outfile not entered */
  48.     make_outname ();
  49.     get_nspaces ();
  50.     break;
  51.  
  52.   default : /* all parms (and maybe more) entered */
  53.     outname = args[3];
  54.     get_nspaces ();
  55.   }
  56. }
  57.  
  58. void make_outname ()  {
  59. char *extension = ".tab", *from, *out;
  60.  
  61.     outname = out = outspec;
  62.     for (from=args[1]; (*from != '.'); out++, from++) {
  63.       if (*from == '\0') break;
  64.       *out = *from;
  65.       }
  66.     *out = '\0';
  67.     outname = strcat (outname,extension);
  68. }
  69.  
  70. void get_nspaces () {
  71. char space[3];
  72.  
  73.     strcpy (space,args[2]);
  74.     if (strlen(space) == 1) {
  75.       if (isdigit(space[0])) nspaces = atoi(space);
  76.       }
  77.     if (strlen(space) == 2) {
  78.       if (isdigit(space[0]) && isdigit(space[1])) \
  79.           nspaces = atoi(space);
  80.       }
  81. }
  82. /************************************************************/
  83. /************************************************************/
  84. void openfiles () {
  85.  
  86. if ((infile=fopen(args[1],"r"))==NULL) {
  87.   fprintf (stderr,
  88.     "couldn't open input file: %s",args[1]);
  89.   exit (1);
  90.   }
  91.  
  92. if ((outfile=fopen(outname,"w"))==NULL) {
  93.   fprintf (stderr,
  94.     "couldn't open output file: %s",outname);
  95.   exit (1);
  96.   }
  97. }
  98. /************************************************************/
  99. /************************************************************/
  100. void dotabs () {
  101.   char inline[147], outline[246];
  102.   int i;
  103.  
  104.   for (i=0; i < nspaces; outline[i++]=' ');
  105.  
  106.   while (*fgets(inline,145,infile) != NULL) {
  107.     outline[i] = '\0';
  108.     strcat (outline,inline);
  109.     fputs (outline,outfile);
  110.     }
  111. }
  112. /************************************************************/
  113.