/*
 * File:       maintenance.c
 * Author:     Shankar chakkere
 * Date:       5/16/97
 * Status:     Working
 * Tested on:  Borland C++  Version 2.0 and cygnus-2.7.2-970404
 * Abstract:   This program, given the current odometer reading will print out
 * the next maintenace scheduled mileage and the list of services to be done.
 * The program is for Honda Civic and it can be modified for any car.
 * Copyright (C) 1999 Shankar Chakkere
 *
 * 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
 * any later version.
 *
 * 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.
 *
 * Visit http://www.fsf.org for more information

 * 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define DIAG 0
#define NUM_ARGS  2
#define USAGE "Usage: maint odometer_reading\n"

list_all (void);
list_7k (void);
list_15k (void);
list_30k (void);
list_45k (void);
list6 (void);
list_105k (void);
list_inspect_15k (void);
list_inspect_7k (void);

/*
 * The array which store the Visual Inspection string that has to be printed
 * at the bottom
 */

char vinspect1[1000] = "";
char vinspect2[1000] = "";

void main(int argc, char * argv[])
{
   long distance;
   int quotient , z;

  if (argc != NUM_ARGS)
   {
    fprintf(stderr, USAGE);
    exit(1);
   }
   distance = atol( argv[1]);

/*
 * All the maintenance schedlue is multiple of 3750 miles.
 * 1 is added because the first maintenace schedule is 3750
 * even if the mileage is less than 3750
 */
   quotient = (distance / 3750L) + 1;

   printf ("%s%ld Miles\n", "Next maintenance Schedule at:\t", 3750L * quotient );
   printf("%s\n", "----------------");

/*
 * oil change, common for all maintenance schedule
 */
   list_all();    

if ((quotient / 2) * 2 == quotient)
   {
   #if DIAG
   printf ("%s\n","7500 Mile Schedule");
   #endif
   list_7k();
   list_inspect_7k();
   }

if ((quotient / 4) * 4 == quotient)
   {
   #if DIAG
   printf ("%s\n","15,000 Mile Schedule");
   #endif
   list_15k();
   }

if((quotient / 8) * 8 == quotient)
   {
   #if DIAG
   printf ("%s\n","30,000 Mile Schedule");
   #endif
   list_30k();
   list_inspect_15k();
   }

if ( quotient == 8)
   {
   /* at 30,000 Miles only
    */
   printf("%s\n","\tInspect valve clearence");
   }

if ((quotient / 12) * 12 == quotient) 
   {
   #if DIAG
   printf ("%s\n","45,000 Mile Schedule");
   #endif
   list_45k();
   }

/* For every 30K miles after including 45k miles
 */
   z =  quotient - 4;    

if (((z) / 8) * 8 == z ) 
   {
   #if DIAG
   printf ("%s\n","45,000 Mile Schedule");
   #endif
   list6();
   }

if ((quotient / 28) * 28 == quotient) 
   {
   #if DIAG
   printf ("%s\n","105,000 Mile Schedule");
   #endif
   list_105k();
   }

if ((strlen(vinspect1) != 0)|| (strlen(vinspect1) != 0))
   {
   printf("%s\n", "Visually Inspect");
   printf("%s\n", "----------------");
   printf("%s\n%s\n", vinspect1, vinspect2);
   printf("%s\n", "----------------");
   }
}

list_all(void)
{
   printf("%s\n","\tReplace engine oil and oil filter");
   return;
}

list_7k(void)
{
   printf("%s%s\n","\tInspect front and rear brakes\n",
   "\tRotate tires");
   return;
}

list_15k(void)
{
   printf("%s%s%s%s\n","\tReplace air cleaner element\n",
   "\tCheck parking brake adjustment\n",
   "\tLubricate locks and hinges\n",
   "\tClean antenna mast");
   return;
}

list_30k(void)
{
   printf("%s%s%s\n","\tReplace spark plugs\n",
   "\tInspect and adjust drive belts\n",
   "\tReplace transmission fluids");
   return;
}

list_45k(void)
{
   printf("%s\n","\tReplace brake fluid");
   return;
}

list6(void)
{
   printf("%s\n","\tReplace engine coolant");
   return;
}

list_105k(void)
{
   printf("%s%s%s\n","\tReplace timing belt\n",
   "\tInspect water pump\n",
   "\tInspect idle speed");
   return;
}

list_inspect_15k(void)
{
   sprintf(vinspect1,"%s%s%s%s%s","\tBrake hoses and lines\n",
   "\tAll fluid levels and condition of fluids\n",
   "\tCooling system hoses and connections\n\tExhaust system\n",
   "\tFuel lines and connections\n\tLights and controls\n",
   "\tVehicle underbody");
   return;
 }

list_inspect_7k(void)
{ printf("%s\n","was here");
   sprintf(vinspect2,"%s%s%s%s","\tTie rod ends\n",
   "\tSteering gear box, and boots\n",
   "\tSuspension components\n",
   "\tDriveshaft boots");
   return;
 }
