File: marquee_ex.c

package info (click to toggle)
libcdk5 5.0.20161210-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,440 kB
  • ctags: 2,833
  • sloc: ansic: 32,375; sh: 4,732; makefile: 1,122; sed: 43; cpp: 41
file content (162 lines) | stat: -rw-r--r-- 4,359 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* $Id: marquee_ex.c,v 1.13 2016/12/04 15:22:16 tom Exp $ */

#include <cdk_test.h>

#ifdef HAVE_XCURSES
char *XCursesProgramName = "marquee_ex";
#endif

static char startAttr[100];
static char endAttr[100];

/*
 * This spits out help about this demo program.
 */
static void help (char *programName)
{
   const char *USAGE = "[-m Message] [-R repeat value] [-d delay value] [-b|r|u|k] [-h]";

   printf ("Usage: %s %s\n", programName, USAGE);
   printf (" -m TEXT   Sets the message to display in the marquee\n");
   printf ("           If no message is provided, one will be created.\n");
   printf (" -R COUNT  Repeat the message the given COUNT.\n");
   printf ("           A of -1 repeats the message forever.\n");
   printf (" -d COUNT  number of milliseconds to delay between repeats.\n");
   printf (" -b        display the message with the bold attribute.\n");
   printf (" -r        display the message with a reversed attribute.\n");
   printf (" -u        display the message with an underline attribute.\n");
   printf (" -k        display the message with the blinking attribute.\n");
}

static void myParseAttr (CDK_PARAMS * params, int lower, int upper)
{
   if (CDKparamString (params, lower) != 0)
   {
      char starting[3];
      char ending[3];

      if (startAttr[0] == '\0')
      {
	 startAttr[0] = '<';
	 endAttr[0] = '<';
      }
      sprintf (starting, "/%c", upper);
      sprintf (ending, "!%c", upper);
      strcat (startAttr, starting);
      strcat (endAttr, ending);
   }
}

int main (int argc, char **argv)
{
   /* *INDENT-OFF* */
   CDKSCREEN	*cdkscreen;
   CDKMARQUEE	*scrollMessage;
   char		message[1024];
   time_t	clck;

   CDK_PARAMS   params;
   char         *mesg;
   int          delay;
   int          repeat;
   /* *INDENT-ON* */


   CDKparseParams (argc, argv, &params, "brkud:R:m:hw:" CDK_MIN_PARAMS);
   myParseAttr (&params, 'b', 'B');
   myParseAttr (&params, 'r', 'R');
   myParseAttr (&params, 'k', 'K');
   myParseAttr (&params, 'u', 'U');
   repeat = CDKparamNumber2 (&params, 'R', 3);
   delay = CDKparamNumber2 (&params, 'd', 5);
   mesg = CDKparamString (&params, 'm');

   if (CDKparamString (&params, 'h') != 0)
      help (argv[0]);

   /* Clean up the strings. */
   cleanChar (message, sizeof (message), '\0');
   cleanChar (startAttr, sizeof (startAttr), '\0');
   cleanChar (endAttr, sizeof (endAttr), '\0');

   /* Put the end of the attributes if they asked for then. */
   if (startAttr[0] == '<')
   {
      strcat (startAttr, ">");
      strcat (endAttr, ">");
   }

   cdkscreen = initCDKScreen (NULL);
   curs_set (0);

   /* Start CDK Colors. */
   initCDKColor ();

   /* Create the marquee. */
   scrollMessage = newCDKMarquee (cdkscreen,
				  CDKparamValue (&params, 'X', CENTER),
				  CDKparamValue (&params, 'Y', TOP),
				  CDKparamValue (&params, 'w', 30),
				  CDKparamValue (&params, 'N', FALSE),
				  CDKparamValue (&params, 'S', TRUE));

   /* Check if the marquee is null. */
   if (scrollMessage == 0)
   {
      /* Exit Cdk. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot create the marquee window. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Draw the CDK screen. */
   refreshCDKScreen (cdkscreen);

   /* Create the marquee message. */
   if (mesg == 0)
   {
      char *currentTime;

      /* Get the current time and chop off the newline. */
      time (&clck);
      currentTime = ctime (&clck);
      currentTime[strlen (currentTime) - 1] = 0;

      if (startAttr[0] != '\0')
      {
	 currentTime[strlen (currentTime) - 1] = '\0';
	 sprintf (message, "%s%s%s (This Space For Rent) ",
		  startAttr,
		  currentTime,
		  endAttr);
      }
      else
      {
	 sprintf (message, "%s (This Space For Rent) ", currentTime);
      }
   }
   else
   {
      if (startAttr[0] != '\0')
      {
	 sprintf (message, "%s%s%s ", startAttr, mesg, endAttr);
      }
      else
      {
	 sprintf (message, "%s ", mesg);
      }
   }

   /* Run the marquee. */
   activateCDKMarquee (scrollMessage, message, delay, repeat, TRUE);
   activateCDKMarquee (scrollMessage, message, delay, repeat, FALSE);
   activateCDKMarquee (scrollMessage, message, delay, repeat, TRUE);

   /* Clean up. */
   destroyCDKMarquee (scrollMessage);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}