Back to index

lightning-sunbird  0.9+nobinonly
escape.c
Go to the documentation of this file.
00001 /* escape.c: Generates XMLterm/LineTerm escape sequences */
00002 
00003 #include <stdio.h>
00004 
00005 int main(int argc, char *argv[])
00006 {
00007   int nparam, j;
00008   char *param1, *param2, *param3, *code, *sparam;
00009 
00010   param1 = NULL;
00011   param2 = NULL;
00012   param3 = NULL;
00013   code =   NULL;
00014   sparam = "";
00015   nparam = 0;
00016 
00017   for (j=1; j<argc; j++) {
00018     if ((*argv[j] >= '0') && (*argv[j] <= '9')) {
00019       if (j == 1) {
00020         param1 = argv[j];
00021         nparam = 1;
00022       } else if (j == 2) {
00023         param2 = argv[j];
00024         nparam = 2;
00025       } else if (j == 3) {
00026         param3 = argv[j];
00027         nparam = 3;
00028       }
00029     } else if (code == NULL) {
00030       code = argv[j];
00031     } else {
00032       sparam = argv[j];
00033     }
00034   }
00035 
00036   if (code == NULL) {
00037     fprintf(stderr, "Usage: %s [<param1> [<param2> [<param3>]]] <code-character> [<string-param>] \n", argv[0]);
00038     return 1;
00039   }
00040 
00041   if (nparam == 0) {
00042     fprintf(stderr, "ESC{%s%s\\n\n", code, sparam);
00043     fprintf(stdout, "\033{%s%s\n", code, sparam);
00044   } else if (nparam == 1) {
00045     fprintf(stderr, "ESC{%s%s%s\\n\n", param1, code, sparam);
00046     fprintf(stdout, "\033{%s%s%s\n", param1, code, sparam);
00047   } else if (nparam == 2) {
00048     fprintf(stderr, "ESC{%s;%s%s%s\\n\n", param1, param2, code, sparam);
00049     fprintf(stdout, "\033{%s;%s%s%s\n", param1, param2, code, sparam);
00050   } else {
00051     fprintf(stderr, "ESC{%s;%s;%s%s%s\\n\n", param1, param2, param3, code, sparam);
00052     fprintf(stdout, "\033{%s;%s;%s%s%s\n", param1, param2, param3, code, sparam);
00053   }
00054 
00055   return 0;
00056 }