/* ** Name: CFCreateConf ** ** Description: ** Create a configuration file. ** ** Inputs: ** path path to configuration file. ** filename filename of configuration file. ** begin Starting line of the confiuration ** ** Outputs: ** loc location structure updated. ** ** Returns: ** OK success ** FAIL failure ** ** History: ** 11-Feb-2000 (fanra01) ** Created. */ STATUS CFCreateConf( char* path, char* filename, LOCATION* loc, PRL begin ) { STATUS status; char* locpath; FILE* fptr; PRL entry = begin; i4 count; /* ** Get the location path */ LOtos( loc, &locpath ); STRCOPY(path, locpath ); if ((status = LOfroms( PATH, locpath, loc )) == OK) { LOfstfile( filename, loc ); if ((status = SIfopen( loc, "w", SI_TXT, 0, &fptr )) == OK) { while ((status == OK) && (entry != NULL)) { status = SIwrite( STRLENGTH(entry->text), entry->text, &count, fptr ); entry = entry->next; } SIclose( fptr ); } else { PRINTF( "Error: %d - Unable to open file %s in %s.\n", status, filename, path ); } } return (status); }
/* ** Name: CFReadConf ** ** Description: ** Read the configuration file a line at a time and build a list. ** ** Inputs: ** path path of file to read ** filename filename of file to read ** ** Outputs: ** loc Location to update with path and filename ** begin Starting line of the confiuration ** end Last line of the configuration ** ** Returns: ** OK success ** FAIL failure ** ** History: ** 11-Feb-2000 (fanra01) ** Created. */ STATUS CFReadConf( char* path, char* filename, LOCATION* loc, PRL* begin ) { STATUS status; char* locpath; FILE* fptr; PRL newline; PRL end; /* ** Get the location path */ LOtos( loc, &locpath ); STRCOPY( path, locpath ); if ((status = LOfroms( PATH, locpath, loc )) == OK) { LOfstfile( filename, loc ); if ((status = SIfopen( loc, "r", SI_TXT, 0, &fptr )) == OK) { do { status = SIgetrec( readbuf, SI_MAX_TXT_REC, fptr ); if (status != ENDFILE) { HALLOC( newline, RL, 1, &status ); if (newline != NULL) { newline->text = STRALLOC( readbuf ); if (*begin == NULL) { *begin = newline; newline->prev = newline; } else { end = (*begin)->prev; end->next = newline; newline->prev = end; (*begin)->prev = newline; } } } }while (status == OK); status = ((status == ENDFILE) || (status == OK)) ? OK : status; SIclose( fptr ); } else { PRINTF( "Error: %d - Unable to open file %s in %s.\n", status, filename, path ); } } return (status); }
int main() { char acStr1[30],acStr2[30],acStr3[30], cChar; int i, iFreqA = 0, iFreqE = 0, iFreqI = 0, iFreqO = 0, iFreqU = 0, iFreqCons = 0; printf("\nEnter string to be copied\n"); gets(acStr1); STRCOPY(acStr1,acStr2); printf("\nCopied String is\n"); puts(acStr2); printf("\nEnter string to find letter frequency\n"); gets(acStr3); for(i=0;acStr3[i]!='\0';i++) { cChar = tolower(acStr3[i]); switch(cChar) { case 'a' : iFreqA++; break; case 'e' : iFreqE++; break; case 'i' : iFreqI++; break; case 'o' : iFreqO++; break; case 'u' : iFreqU++; break; case ' ' : break; default : iFreqCons++; } } printf("\nFrequency of vowel 'A' is : %d\n",iFreqA); printf("\nFrequency of vowel 'E' is : %d\n",iFreqE); printf("\nFrequency of vowel 'I' is : %d\n",iFreqI); printf("\nFrequency of vowel 'O' is : %d\n",iFreqO); printf("\nFrequency of vowel 'U' is : %d\n",iFreqU); printf("\nThe no of consonants is : %d\n",iFreqCons); return 0; }
char *__Menu_PrintTitle(char *name) { //static char buffer[MAX_CHARACTERS + 4]; static char buffer[200]; int len = con_len(name); /* Clear buffer */ memset(buffer, 0, sizeof(buffer)); /* Check string length */ if (len >= MAX_CHARACTERS) { //strncpy(buffer, name, MAX_CHARACTERS - 4); STRCOPY(buffer, name); con_trunc(buffer, MAX_CHARACTERS - 4); strcat(buffer, "..."); return buffer; } return name; }
void get_time2(long long *t, char *s) { if (!t) return; if (*t == 0) *t = gettime(); char c; char *p; char ss[32]; char *dir; int len; long long tt = gettime(); p = strchr(s, '.'); if (p) p++; else p = s; STRCOPY(ss, p); len = strlen(ss) - 1; c = ss[len]; if (c == '1') { dir = "-->"; ss[len] = 0; } else if (c == '2') { dir = "<--"; ss[len] = 0; } else return; //dir = "---"; dbg_printf("[%.3f] %s %s\n", diff_fsec(TIME.boot1, tt), dir, ss); if (CFG.debug) __console_flush(0); }
void ppbuiltin(void) { register int c; register char* p; register char* a; int n; int op; char* token; char* t; long number; long onumber; struct ppinstk* in; struct pplist* list; struct ppsymbol* sym; Sfio_t* sp; number = pp.state; pp.state |= DISABLE|FILEPOP|NOSPACE; token = pp.token; p = pp.token = pp.tmpbuf; *(a = pp.args) = 0; if ((c = pplex()) != T_ID) { error(2, "%s: #(<identifier>...) expected", p); *p = 0; } switch (op = (int)hashget(pp.strtab, p)) { case V_DEFAULT: n = 0; p = pp.token = pp.valbuf; if ((c = pplex()) == ',') { op = -1; c = pplex(); } pp.state &= ~NOSPACE; for (;;) { if (!c) { error(2, "%s in #(...) argument", pptokchr(c)); break; } if (c == '(') n++; else if (c == ')' && !n--) break; else if (c == ',' && !n && op > 0) op = 0; if (op) pp.token = pp.toknxt; c = pplex(); } *pp.token = 0; pp.token = token; pp.state = number; break; case V_EMPTY: p = pp.valbuf; if ((c = pplex()) == ')') *p = '1'; else { *p = '0'; n = 0; for (;;) { if (!c) { error(2, "%s in #(...) argument", pptokchr(c)); break; } if (c == '(') n++; else if (c == ')' && !n--) break; c = pplex(); } } *(p + 1) = 0; pp.token = token; pp.state = number; break; case V_ITERATE: n = 0; pp.token = pp.valbuf; if ((c = pplex()) != T_ID || !(sym = ppsymref(pp.symtab, pp.token)) || !sym->macro || sym->macro->arity != 1 || (c = pplex()) != ',') { error(2, "#(%s <macro(x)>, ...) expected", p); for (;;) { if (!c) { error(2, "%s in #(...) argument", pptokchr(c)); break; } if (c == '(') n++; else if (c == ')' && !n--) break; c = pplex(); } *pp.valbuf = 0; } else while (c != ')') { p = pp.token; if (pp.token > pp.valbuf) *pp.token++ = ' '; STRCOPY(pp.token, sym->name, a); *pp.token++ = '('; if (!c || !(c = pplex())) { pp.token = p; error(2, "%s in #(...) argument", pptokchr(c)); break; } pp.state &= ~NOSPACE; while (c) { if (c == '(') n++; else if (c == ')' && !n--) break; else if (c == ',' && !n) break; pp.token = pp.toknxt; c = pplex(); } *pp.token++ = ')'; pp.state |= NOSPACE; } p = pp.valbuf; pp.token = token; pp.state = number; break; default: pp.token = token; while (c != ')') { if (!c) { error(2, "%s in #(...) argument", pptokchr(c)); break; } if ((c = pplex()) == T_ID && !*a) strcpy(a, pp.token); } pp.state = number; switch (op) { case V_ARGC: c = -1; for (in = pp.in; in; in = in->prev) if ((in->type == IN_MACRO || in->type == IN_MULTILINE) && (in->symbol->flags & SYM_FUNCTION)) { c = *((unsigned char*)(pp.macp->arg[0] - 2)); break; } sfsprintf(p = pp.valbuf, MAXTOKEN, "%d", c); break; case V_BASE: p = (a = strrchr(error_info.file, '/')) ? a + 1 : error_info.file; break; case V_DATE: if (!(p = pp.date)) { time_t tm; time(&tm); a = p = ctime(&tm) + 4; *(p + 20) = 0; for (p += 7; *p = *(p + 9); p++); pp.date = p = strdup(a); } break; case V_FILE: p = error_info.file; break; case V_LINE: sfsprintf(p = pp.valbuf, MAXTOKEN, "%d", error_info.line); break; case V_PATH: p = pp.path; break; case V_SOURCE: p = error_info.file; for (in = pp.in; in->prev; in = in->prev) if (in->prev->type == IN_FILE && in->file) p = in->file; break; case V_STDC: p = pp.valbuf; p[0] = ((pp.state & (COMPATIBILITY|TRANSITION)) || (pp.mode & (HOSTED|HOSTEDTRANSITION)) == (HOSTED|HOSTEDTRANSITION)) ? '0' : '1'; p[1] = 0; break; case V_TIME: if (!(p = pp.time)) { time_t tm; time(&tm); p = ctime(&tm) + 11; *(p + 8) = 0; pp.time = p = strdup(p); } break; case V_VERSION: p = (char*)pp.version; break; case V_DIRECTIVE: pp.state |= NEWLINE; pp.mode |= RELAX; strcpy(p = pp.valbuf, "#"); break; case V_GETENV: if (!(p = getenv(a))) p = ""; break; case V_GETMAC: p = (sym = pprefmac(a, REF_NORMAL)) ? sym->macro->value : ""; break; case V_GETOPT: sfsprintf(p = pp.valbuf, MAXTOKEN, "%ld", ppoption(a)); break; case V_GETPRD: p = (list = (struct pplist*)hashget(pp.prdtab, a)) ? list->value : ""; break; case V__PRAGMA: if ((c = pplex()) == '(') { number = pp.state; pp.state |= NOSPACE|STRIP; c = pplex(); pp.state = number; if (c == T_STRING || c == T_WSTRING) { if (!(sp = sfstropen())) error(3, "temporary buffer allocation error"); sfprintf(sp, "#%s %s\n", dirname(PRAGMA), pp.token); a = sfstruse(sp); if ((c = pplex()) == ')') { pp.state |= NEWLINE; PUSH_BUFFER(p, a, 1); } sfstrclose(sp); } } if (c != ')') error(2, "%s: (\"...\") expected", p); return; case V_FUNCTION: #define BACK(a,p) ((a>p)?*--a:(number++?0:((p=pp.outbuf+PPBUFSIZ),(a=pp.outbuf+2*PPBUFSIZ),*--a))) #define PEEK(a,p) ((a>p)?*(a-1):(number?0:*(pp.outbuf+2*PPBUFSIZ-1))) number = pp.outbuf != pp.outb; a = pp.outp; p = pp.outb; op = 0; while (c = BACK(a, p)) { if (c == '"' || c == '\'') { op = 0; while ((n = BACK(a, p)) && n != c || PEEK(a, p) == '\\'); } else if (c == '\n') { token = a; while (c = BACK(a, p)) if (c == '\n') { a = token; break; } else if (c == '#' && PEEK(a, p) == '\n') break; } else if (c == ' ') /*ignore*/; else if (c == '{') /* '}' */ op = 1; else if (op == 1) { if (c == ')') { op = 2; n = 1; } else op = 0; } else if (op == 2) { if (c == ')') n++; else if (c == '(' && !--n) op = 3; } else if (op == 3) { if (ppisidig(c)) { for (t = p, token = a, onumber = number; ppisidig(PEEK(a, p)) && a >= p; BACK(a, p)); p = pp.valbuf + 1; if (a > token) { for (; a < pp.outbuf+2*PPBUFSIZ; *p++ = *a++); a = pp.outbuf; } for (; a <= token; *p++ = *a++); *p = 0; p = pp.valbuf + 1; if (streq(p, "for") || streq(p, "if") || streq(p, "switch") || streq(p, "while")) { op = 0; p = t; number = onumber; continue; } } else op = 0; break; } } if (op == 3) p = strncpy(pp.funbuf, p, sizeof(pp.funbuf) - 1); else if (*pp.funbuf) p = pp.funbuf; else p = "__FUNCTION__"; break; default: if (pp.builtin && (a = (*pp.builtin)(pp.valbuf, p, a))) p = a; break; } break; } if (strchr(p, MARK)) { a = pp.tmpbuf; strcpy(a, p); c = p != pp.valbuf; p = pp.valbuf + c; for (;;) { if (p < pp.valbuf + MAXTOKEN - 2) switch (*p++ = *a++) { case 0: break; case MARK: *p++ = MARK; /*FALLTHROUGH*/ default: continue; } break; } p = pp.valbuf + c; } if (p == pp.valbuf) PUSH_STRING(p); else { if (p == pp.valbuf + 1) *pp.valbuf = '"'; else { if (strlen(p) > MAXTOKEN - 2) error(1, "%-.16s: builtin value truncated", p); sfsprintf(pp.valbuf, MAXTOKEN, "\"%-.*s", MAXTOKEN - 2, p); } PUSH_QUOTE(pp.valbuf, 1); } }