/[gmemo]/gmemo/src/gmemo_main.c
ViewVC logotype

Diff of /gmemo/src/gmemo_main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by flashcode, Tue May 27 19:46:15 2003 UTC revision 1.2 by TwinSun, Mon Jun 2 15:14:23 2003 UTC
# Line 24  Line 24 
24  #endif  #endif
25    
26  #ifdef _WIN32  #ifdef _WIN32
27      #include <windows.h>  #include <windows.h>
28  #endif  #endif
29    
30  #include <stdlib.h>  #include <stdlib.h>
# Line 36  Line 36 
36  #include "gmemo_memo.h"  #include "gmemo_memo.h"
37  #include "gmemo_display.h"  #include "gmemo_display.h"
38    
39    /* Add getopt_long function to parse command line args */
40    #include "getopt.h"
41    
42  #ifdef _WIN32  #ifdef _WIN32
43  int     argc = 0;  int     argc = 0;
# Line 50  char    *argv[128]; Line 52  char    *argv[128];
52  #ifdef _WIN32  #ifdef _WIN32
53  void explode_args_win32(char *command_line)  void explode_args_win32(char *command_line)
54  {  {
55      char    *pos;    char    *pos;
56            
57      argc = 1;    argc = 1;
58      argv[0] = (char *)malloc(1);    argv[0] = (char *)malloc(1);
59      argv[0][0] = '\0';    argv[0][0] = '\0';
60      while (command_line != NULL)    while (command_line != NULL)
61      {      {
62          if (command_line[0] == '\0')        if (command_line[0] == '\0')
63              return;          return;
64          pos = strchr(command_line, ' ');        pos = strchr(command_line, ' ');
65          if (pos == NULL)        if (pos == NULL)
66          {          {
67              argv[argc] = (char *)malloc(strlen(command_line)+1);            argv[argc] = (char *)malloc(strlen(command_line)+1);
68              strcpy(argv[argc], command_line);            strcpy(argv[argc], command_line);
69              argc++;            argc++;
70              command_line = NULL;            command_line = NULL;
71          }          }
72          else        else
73          {          {
74              pos[0] = '\0';            pos[0] = '\0';
75              argv[argc] = (char *)malloc(strlen(command_line)+1);            argv[argc] = (char *)malloc(strlen(command_line)+1);
76              strcpy(argv[argc], command_line);            strcpy(argv[argc], command_line);
77              argc++;            argc++;
78              command_line = pos+1;            command_line = pos+1;
79              while (command_line[0] == ' ')            while (command_line[0] == ' ')
80                  command_line++;              command_line++;
81          }          }
82      }      }
83  }  }
# Line 84  void explode_args_win32(char *command_li Line 86  void explode_args_win32(char *command_li
86  /*  /*
87   * gmemo_parse_args: parse command line args   * gmemo_parse_args: parse command line args
88   */   */
   
89  void gmemo_parse_args(int argc, char *argv[])  void gmemo_parse_args(int argc, char *argv[])
90  {  {
91      int     i;  
92          int c;
93      for (i = 1; i < argc; i++)  
94      while (1)
95      {      {
96          if ( (strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--daemon") == 0) )  
97          {        /* getopt_long stores the option index here. */
98              gmemo_daemon = TRUE;        int option_index = 0;
99          }  
100          else if ( (strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0) )  
101          {        /* Availeable options */
102              gmemo_display_usage();        static struct option long_options[] =
             gmemo_exit(0);  
         }  
         else if ( (strcmp(argv[i], "-l") == 0) || (strcmp(argv[i], "--licence") == 0) )  
         {  
             gmemo_display_licence();  
             gmemo_exit(0);  
         }  
         else if ( (strcmp(argv[i], "-q") == 0) || (strcmp(argv[i], "--quiet") == 0) )  
         {  
             gmemo_quiet = TRUE;  
         }  
         else if ( (strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--seconds") == 0) )  
         {  
             gmemo_display_seconds = TRUE;  
         }  
         else if ( (strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--verbose") == 0) )  
         {  
             gmemo_verbose = TRUE;  
         }  
         else if ( (strcmp(argv[i], "-w") == 0) || (strcmp(argv[i], "--withdrawn") == 0) )  
103          {          {
104              gmemo_withdrawn = TRUE;            {"daemon", no_argument, 0, 'd'},
105          }            {"help",   no_argument, 0, 'h'},
106          else            {"licence", no_argument, 0, 'l'},
107              {"quiet", no_argument, 0,'q'},
108              {"seconds", no_argument, 0,'s'},
109              {"verbose",no_argument,0,'v'},
110              {"withdrawn",no_argument,0,'w'},
111              {0, 0, 0, 0}
112            };
113    
114          c = getopt_long (argc, argv, "dhlqsvw",
115                           long_options, &option_index);
116    
117          /* Detect the end of the options. */
118          if (c == -1)
119            break;
120    
121          switch (c)
122          {          {
123              GMEMO_WARNING("parsing command line: unknown parameter '%s', ignored", argv[i]);  
124            case 'd':
125              gmemo_daemon = TRUE;
126              break;
127    
128            case 'h':
129              gmemo_display_usage();
130              gmemo_exit(0);
131              break;
132    
133            case 'l':
134              gmemo_display_licence();
135              gmemo_exit(0);
136              break;
137    
138            case 'q':
139              gmemo_quiet = TRUE;
140              break;
141    
142            case 's':
143              gmemo_display_seconds = TRUE;
144              break;
145    
146            case 'v':
147              gmemo_verbose = TRUE;
148              break;
149    
150            case 'w':
151              gmemo_withdrawn = TRUE;
152              break;
153    
154            case '?':
155              /* getopt_long already printed an error message. */
156              break;
157    
158            default:
159              abort ();
160    
161          }          }
162      }      }
163        
164      if (gmemo_daemon && gmemo_withdrawn)    if (gmemo_daemon && gmemo_withdrawn)
165      {      {
166          GMEMO_ERROR("daemon and withdrawn are incompatible options");        GMEMO_ERROR("daemon and withdrawn are incompatible options");
167          gmemo_exit(1);        gmemo_exit(1);
168      }      }
169            
170      if (gmemo_win_width == -1)    if (gmemo_win_width == -1)
171          gmemo_win_width = (gmemo_withdrawn) ? 64 : 220;      gmemo_win_width = (gmemo_withdrawn) ? 64 : 220;
172      if (gmemo_win_height == -1)    if (gmemo_win_height == -1)
173          gmemo_win_height = (gmemo_withdrawn) ? 64 : 48;      gmemo_win_height = (gmemo_withdrawn) ? 64 : 48;
174            
175      if (gmemo_verbose)    if (gmemo_verbose)
176      {      {
177          GMEMO_MESSAGE("finished parsing command line. Results below :");        GMEMO_MESSAGE("finished parsing command line. Results below :");
178          GMEMO_MESSAGE("application type is %s", (gmemo_daemon) ? "daemon" : ((gmemo_withdrawn) ? "withdrawn" : "gtk"));        GMEMO_MESSAGE("application type is %s", (gmemo_daemon) ? "daemon" : ((gmemo_withdrawn) ? "withdrawn" : "gtk"));
179          GMEMO_MESSAGE("using display '%s'", gmemo_display);        GMEMO_MESSAGE("using display '%s'", gmemo_display);
180          GMEMO_MESSAGE("window width  = %d", gmemo_win_width);        GMEMO_MESSAGE("window width  = %d", gmemo_win_width);
181          GMEMO_MESSAGE("window height = %d", gmemo_win_height);        GMEMO_MESSAGE("window height = %d", gmemo_win_height);
182          GMEMO_MESSAGE("digits size   = %d\n", gmemo_size_digits);        GMEMO_MESSAGE("digits size   = %d\n", gmemo_size_digits);
183      }      }
184            
185      if (gmemo_withdrawn)    if (gmemo_withdrawn)
186      {      {
187          GMEMO_ERROR("window maker stuff not developed !");        GMEMO_ERROR("window maker stuff not developed !");
188          gmemo_exit(1);        gmemo_exit(1);
189      }      }
190    
191  }  }
192    
193    
194  /*  /*
195   * main: main function for gmemo (except for Gnome applet)   * main: main function for gmemo (except for Gnome applet)
196   */   */
# Line 162  void gmemo_parse_args(int argc, char *ar Line 198  void gmemo_parse_args(int argc, char *ar
198  #ifdef _WIN32  #ifdef _WIN32
199  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
200  #else  #else
201  int main (int argc, char *argv[])       int main (int argc, char *argv[])
202  #endif  #endif
203  {  {
204      // gtk2.0: gdk_draw_layout () et pango_layout_new pour faire le layout...    // gtk2.0: gdk_draw_layout () et pango_layout_new pour faire le layout...
205    
206      // Initialize the i18n stuff    // Initialize the i18n stuff
207      //bindtextdomain (PACKAGE, GNOMELOCALEDIR);    //bindtextdomain (PACKAGE, GNOMELOCALEDIR);
208      //textdomain (PACKAGE);    //textdomain (PACKAGE);
209            
210      #ifdef _WIN32  #ifdef _WIN32
211      explode_args_win32(szCmdLine);    explode_args_win32(szCmdLine);
212      gtk_init(NULL, NULL);    gtk_init(NULL, NULL);
213      #else  #else
214      gtk_init(&argc, &argv);    gtk_init(&argc, &argv);
215      #endif  #endif
216            
217      gmemo_init();    gmemo_init();
218      gmemo_parse_args(argc, argv);    gmemo_parse_args(argc, argv);
219            
220      load_feasts();    load_feasts();
221      memos = NULL;    memos = NULL;
222      load_memos();    load_memos();
223      /*if (!save_memos())    /*if (!save_memos())
224          GMEMO_WARNING("error saving memos file");*/      GMEMO_WARNING("error saving memos file");*/
225            
226      #ifndef WIN32  #ifndef WIN32
227      signal(SIGUSR1, signal_usr1);    signal(SIGUSR1, signal_usr1);
228      #endif  #endif
229            
230      gmemo_create_window(argc, argv);    gmemo_create_window(argc, argv);
231            
232      gtk_main();    gtk_main();
233            
234      return 0;    return 0;
235  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26