Main Page | Class List | File List | Class Members | File Members

input.c File Reference

#include "standard.h"
#include <stdarg.h>
#include "ansi.h"

Go to the source code of this file.

Defines

#define STRLEN   256

Functions

int exist (char *fn)
void banner (char *message)
void hdr (char *msg)
void hdr2 (char *msg)
void prompt (char *s)
void read_line1 (char *s)
int strip_comments (char *s)
void strip_ending_whitespace (char *s)
void read_line (char *s)
char upper (char c)
int equals (char *s1, char *s2)
int get_int (void)
double get_real (void)
void get_str (char *s)
char * text (int x)
void open_input_file (char *fn)
void close_input_file (void)
int eof_input_file ()

Variables

int debug
FILE * input_file
char input_filename [STRLEN]
int line_number = 0


Define Documentation

#define STRLEN   256
 

Definition at line 15 of file input.c.


Function Documentation

void banner char *  message  ) 
 

Definition at line 37 of file input.c.

00038 {
00039   int i;
00040   int x = (75 - strlen(message)) / 2;
00041 
00042   printf("+-----------------------------------------------------------------------------+\n");
00043   printf(": ");
00044   for (i=0; i<x; i++)
00045     putchar(' ');
00046   printf(message);
00047   if (((75 - strlen(message)) % 2) == 1)
00048     putchar(' ');
00049   for (i=0; i<x; i++)
00050     putchar(' ');  
00051   printf(" :\n");
00052   printf("+-----------------------------------------------------------------------------+\n");
00053 }

void close_input_file void   ) 
 

Definition at line 290 of file input.c.

References input_file.

Referenced by set_config().

00291 {
00292   if ((input_file != stdin) && (input_file != NULL))
00293     fclose(input_file);
00294   input_file = stdin;
00295 }

int eof_input_file  ) 
 

Definition at line 298 of file input.c.

References input_file.

Referenced by audio_config(), channel_config(), control_config(), get_config(), mux_config(), mux_table_config(), side_config(), and video_config().

00299 {
00300   return (feof(input_file));
00301 }

int equals char *  s1,
char *  s2
 

Definition at line 186 of file input.c.

References upper().

Referenced by audio_config(), channel_config(), control_config(), do_cmd(), get_config(), mux_config(), mux_table_config(), set_config(), side_config(), strtobch_type(), and video_config().

00190 {
00191   int i=0;
00192   while ((s1[i]!='\0') && (s2[i]!='\0') && (upper(s1[i])==upper(s2[i])))
00193     i++;
00194   if (s1[i]==s2[i])
00195     return 1;
00196   else
00197     return 0;
00198 }

int exist char *  fn  ) 
 

Definition at line 23 of file input.c.

00027 {
00028   int x = open(fn);
00029   if (x != -1) {
00030     close(x);
00031     x = 1;
00032   } else
00033     x = 0;
00034   return (x);
00035 }

int get_int void   ) 
 

Definition at line 201 of file input.c.

References input_file, and read_line().

00205 {
00206   char s[STRLEN];
00207   int x;
00208 
00209   read_line(s);
00210   x = atoi(s);
00211   if (input_file != stdin)
00212     printf("%d\n", x);
00213   return(x);
00214 }

double get_real void   ) 
 

Definition at line 217 of file input.c.

References input_file, and read_line().

00221 {
00222   char s[STRLEN];
00223   double x;
00224   read_line(s);
00225   x = atof(s);
00226   if (input_file != stdin)
00227     printf("%f\n", x);
00228   return(x);
00229 }

void get_str char *  s  ) 
 

Definition at line 233 of file input.c.

References input_file, and read_line().

Referenced by audio_config(), channel_config(), control_config(), get_config(), mux_config(), mux_table_config(), side_config(), and video_config().

00237 {
00238   read_line(s);
00239   if ((input_file != stdin) && (debug))
00240     printf("%s\n", s);
00241 }

void hdr char *  msg  ) 
 

Definition at line 64 of file input.c.

00065 {
00066   printf("              ##################################################\n");
00067   printf("              # %-46s #\n", msg);
00068   printf("              ##################################################\n");
00069 }

void hdr2 char *  msg  ) 
 

Definition at line 72 of file input.c.

00073 {
00074   printf("          +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+\n");
00075   printf("          | %-55s |\n", msg);
00076   printf("          +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+\n");
00077 }

void open_input_file char *  fn  ) 
 

Definition at line 276 of file input.c.

References error(), input_file, input_filename, and line_number.

Referenced by set_config().

00277 {
00278   if ((input_file != stdin) && (input_file != NULL))
00279     fclose(stdin);
00280   input_file = fopen(fn, "r");
00281   if (input_file != NULL) {
00282     line_number = 0;
00283   }
00284   else {
00285     error("open_input_file", "Couldn't open config file");
00286   }
00287   strcpy(input_filename, fn);
00288 }

void prompt char *  s  ) 
 

Definition at line 79 of file input.c.

00080 {
00081   printf("+-----------------------------------------------------------------------------+\n");
00082   printf(":                                                                             :\n");
00083   printf("+-----------------------------------------------------------------------------+\n");
00084   up(2);
00085   right(2);
00086   printf(s);
00087   fflush(stdout);
00088 }

void read_line char *  s  )  [static]
 

Definition at line 161 of file input.c.

References read_line1(), strip_comments(), and strip_ending_whitespace().

00167 {
00168   read_line1(s);
00169   strip_comments(s);
00170   strip_ending_whitespace(s);
00171 }

void read_line1 char *  s  )  [static]
 

Definition at line 91 of file input.c.

References input_file, and line_number.

00095 {
00096   int i = 0;
00097   int done = 0;
00098   int escape = 0;
00099   char c;
00100 
00101   s[0]='\0';
00102 
00103   while(!done && !feof(input_file)) {
00104     c = fgetc(input_file);
00105     if (escape) {
00106       s[i++]=c;
00107       escape=0;
00108     }
00109     else {
00110       if (c == '\\') {
00111         escape = 1;
00112       }
00113       else {
00114         if (c == '\n'){
00115           done = 1;
00116         }
00117         else {
00118           if (feof(input_file))
00119             done = 1;
00120           else
00121             s[i++] = c;
00122         }
00123       }
00124     }
00125   }
00126   s[i]='\0';
00127   line_number++;
00128 }

int strip_comments char *  s  )  [static]
 

Definition at line 131 of file input.c.

00135 {
00136   int i=0;
00137   int comments=0;
00138   int len=strlen(s);
00139   while (i < strlen(s)) {
00140     if ((s[i]=='#') || (s[i]==';')) {
00141       comments = 1;
00142       s[i]='\0';
00143     }
00144     i++;
00145   }
00146   return(comments);
00147 }

void strip_ending_whitespace char *  s  )  [static]
 

Definition at line 150 of file input.c.

00151 {
00152   int x = strlen(s)-1;
00153   if (x > 0) {
00154     while (x > 0 && (s[x]==' ' || s[x]=='\t')) {
00155       s[x] = '\0';
00156       x--;
00157     }
00158   }
00159 }

char* text int  x  ) 
 

Definition at line 244 of file input.c.

00248 {
00249   static char sx[STRLEN];
00250   switch(x) {
00251     case 0: return("Zero");
00252     case 1: return("One");
00253     case 2: return("Two");
00254     case 3: return("Three");
00255     case 4: return("Four");
00256     case 5: return("Five");
00257     case 6: return("Six");
00258     case 7: return("Seven");
00259     case 8: return("Eight");
00260     case 9: return("Nine");
00261     case 10: return("Ten");
00262     case 11: return("Eleven");
00263     case 12: return("Twelve");
00264     case 13: return("Thirteen");
00265     case 14: return("Fourteen");
00266     case 15: return("Fifteen");
00267     case 16: return("Sixteen");
00268     case 17: return("Seventeen");
00269     case 18: return("Eighteen");
00270     case 19: return("Nineteen");
00271     case 20: return("Twenty");
00272     default: sprintf(sx, "%d", x); return(sx);
00273   }
00274 }

char upper char  c  ) 
 

Definition at line 174 of file input.c.

Referenced by equals().

00179 {
00180   if ((c >= 'a') && (c <= 'z'))
00181     return (c - 'a' + 'A');
00182   else
00183     return c;
00184 }


Variable Documentation

int debug
 

Definition at line 23 of file main.c.

FILE* input_file [static]
 

Definition at line 18 of file input.c.

Referenced by close_input_file(), eof_input_file(), get_int(), get_real(), get_str(), open_input_file(), and read_line1().

char input_filename[STRLEN] [static]
 

Definition at line 19 of file input.c.

Referenced by open_input_file().

int line_number = 0 [static]
 

Definition at line 20 of file input.c.

Referenced by open_input_file(), and read_line1().


Generated on Sun Jul 16 16:27:47 2006 by  doxygen 1.3.9.1