bugfixed command parsing, DISPLAY -> USE_NCURSES
authorhackbard <hackbard>
Sun, 9 May 2004 00:42:32 +0000 (00:42 +0000)
committerhackbard <hackbard>
Sun, 9 May 2004 00:42:32 +0000 (00:42 +0000)
src/ivac.c

index 8b8acbc..1018192 100644 (file)
@@ -21,7 +21,7 @@
  *
  */
 
-// #define DISPLAY
+// #define USE_NCURSES
 
 #include "ivac.h"
 
@@ -32,8 +32,13 @@ int main(int argc,char **argv) {
   t_ivac ivac;
   int i;
 
-  /* set username (futur: read from config or entered later) */
-  strcpy(ivac.username,"hackbard");
+  if(argc!=2) {
+    printf("\nusage: %s <username>\n\n",argv[0]);
+    return ERROR;
+  }
+
+  /* set username */
+  strncpy(ivac.username,argv[1],CHAR_USERNAME);
   for(i=0;i<IVAC_CONSOLE_LEN;i++)
     memset(ivac.console[i],0,IVAC_CONSOLE_STRING_LEN);
 
@@ -66,14 +71,10 @@ int main(int argc,char **argv) {
   event_math(0,&(ivac.event),READ,ADD);
 
   /* display init */
-#ifdef DISPLAY
   display_init(&(ivac.display));
-#endif
 
   /* display */
-#ifdef DISPLAY
   ivac_display(&(ivac.display));
-#endif
 
   /* start event system - callbacks used: ivac_event_cb + ivac_regular_cb */
   event_start(&(ivac.event),(void *)&ivac,ivac_event_cb,ivac_regular_cb);
@@ -88,7 +89,7 @@ int ivac_shutdown(t_ivac *ivac) {
   network_shutdown(&(ivac->net));
   input_shutdown(&(ivac->input));
   event_stop(&(ivac->event));
-#ifdef DISPLAY
+#ifdef USE_NCURSES
   display_shutdown(&(ivac->display));
 #endif
 
@@ -190,7 +191,7 @@ int ivac_event_cb(t_event *event,void *ptr) {
     input_get_event(&(ivac->input),ivac_parse_command,ivac);
 
   /* display ivac gui */
-#ifdef DISPLAY
+#ifdef USE_NCURSES
   ivac_display_content(ivac);
 #endif
     
@@ -279,7 +280,7 @@ int ivac_parse_command(t_input *input,void *ptr) {
       if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]);
       else channel=-1;
       if((channel>=0)&&(channel<MAX_CONNECTIONS)) {
-        if(!ivac->net.connection[channel].status&C_INFO_A)
+        if(!(ivac->net.connection[channel].status&C_INFO_A))
           sprintf(c_str,"channel %02d: channel not configured",channel);
         else {
           if(ivac->net.connection[channel].status&C_IN_USE)
@@ -298,7 +299,7 @@ int ivac_parse_command(t_input *input,void *ptr) {
       if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]);
       else channel=-1;
       if((channel>=0)&&(channel<MAX_CONNECTIONS)) {
-        if(!ivac->net.connection[channel].status&C_ESTABL)
+        if(!(ivac->net.connection[channel].status&C_ESTABL))
           sprintf(c_str,"channel %02d: no active connection",channel);
         else {
           ivac->net.connection[channel].status|=C_HANGUP;
@@ -353,6 +354,7 @@ int ivac_parse_command(t_input *input,void *ptr) {
 
 int ivac_display_head(t_display *display) {
 
+#ifdef USE_NCURSES
   int x,y;
 
   move(0,0);
@@ -363,18 +365,25 @@ int ivac_display_head(t_display *display) {
   move(2,0);
   for(x=0;x<display->max_x;x++) addch('#');
   refresh();
+#else
+  puts("#########################################################");
+  puts("##### ivac - -  Copyright (C) 2004 Frank Zirkelbach #####");
+  puts("#########################################################");
+#endif
 
   return SUCCESS;
 }
 
 int ivac_display_box(t_display *display) {
-  
+#ifdef USE_NCURSES 
   int x,y;
 
   for(y=IVAC_PROMPT_LEN;y<display->max_y-IVAC_PROMPT_LEN;y++) {
     mvaddch(y,0,'#');
     mvaddch(y,display->max_x-1,'#');
   }
+#endif
 
   return SUCCESS;
 }
@@ -488,7 +497,7 @@ int ivac_add_to_monitor(t_ivac *ivac,char *msg) {
 
   for(i=0;i<IVAC_CONSOLE_LEN;i++)
     printf("[ivac] console line %d: %s\n",i,ivac->console[i]);
-#ifdef DISPLAY
+#ifdef USE_NCURSES
   ivac_display_console_content(ivac);
 #endif