static void ExecDefault(const char *param) { char *temp = strmalloc(param); char *s = skip_ident(temp); int save = *s; int isClass; *s = 0; if (!*temp) { free(temp); temp = strmalloc(NAME_KEYWORD); isClass = (is_class(temp) != 0); } else { isClass = (is_class(temp) != 0); *s = (char) save; } if (isClass) { flt_init_attr(temp); VERBOSE(1, ("set default_attr '%s' %p", default_attr, default_attr)); } else { VERBOSE(1, ("not a class:%s", temp)); } free(temp); }
static COUNTS * chrcount(char *path) { char temp[1024]; char leaf[1024]; size_t used = 0; size_t need = 2; COUNTS *result = typeCalloc(need, COUNTS); if (isdirectory(path)) { FILE *pp = popen("ls -1 -a", "r"); if (pp != 0) { while (fgets(leaf, sizeof(leaf), pp) != 0) { trim(leaf); sprintf(temp, "%s/%s", path, leaf); if ((used + 1) >= need) { need = (used + 1) * 2; result = realloc(result, sizeof(COUNTS) * need); } if ((result[used].count = do_count(temp)) >= 0) { result[used].name = strmalloc(leaf); used++; result[used].name = 0; } } pclose(pp); } } else { result[0].name = strmalloc(path); result[0].count = do_count(path); } return result; }
/* FIXME */ static void init_data(KEYWORD * data, const char *name, const char *attribute, int classflag, char *flag) { data->kw_name = strmalloc(name); data->kw_size = strlen(data->kw_name); data->kw_attr = strmalloc(attribute); data->kw_flag = (flag != 0) ? strmalloc(flag) : 0; data->kw_type = (unsigned short) classflag; data->kw_used = 2; }
static void ExecClass(const char *param) { char *temp = strmalloc(param); parse_keyword(temp, 1); free(temp); }
/* * Create pipe with either write- _or_ read-semantics. Fortunately for us, * on SYS_MSDOS, we don't need both at the same instant. */ int inout_popen(FILE **fr, FILE **fw, char *cmd) { char *type = (fw != 0) ? "w" : "r"; static FILE *pp[2] = {0, 0}; int fd; TRACE(("inout_popen(fr=%p, fw=%p, cmd='%s')\n", fr, fw, cmd)); ffstatus = file_is_pipe; fileeof = FALSE; append_libdir_to_path(); /* Create the file that will hold the pipe's content */ if ((fd = createTemp(type)) >= 0) { if (fw == 0) { *fr = pp[0] = readPipe(cmd, -1, fd); myWrtr = 0; myPipe = &pp[0]; /* "fr" may be stack-based. */ myCmds = 0; } else { *fw = pp[1] = fdopen(fd, type); myPipe = fr; myWrtr = &pp[1]; /* "fw" may be stack-based. */ myCmds = strmalloc(cmd); } } return TRUE; }
/* i'm not even going to try to justify this. -pgf */ static void personals(int n) { #if !SMALLER const char **cmdp = NULL; static const char *pgfcmds[] = { "bind-key split-current-window ^T", "bind-key next-window ^N", "bind-key previous-window ^P", "set ai atp nobl ul=0 sw=4 csw=4 timeoutlen=50 check-modtime visual-matches=underline", NULL }; if (n == 11) cmdp = pgfcmds; if (n == -11) *(int *) (1) = 42; /* test core dumps */ if (!cmdp) return; while (*cmdp) { char *line = strmalloc(*cmdp); (void) docmd(line, TRUE, FALSE, 1); free(line); cmdp++; } #else (void) n; #endif }
static char * parse_arglist(char *name, char *s, char ***args, int *parens) { char *r; char *v; int quoted; size_t count; size_t used; char *t; int processing; t = SkipBlanks(s); if (*parens == 0) { quoted = 0; count = 0; used = 0; if (*t == L_PAREN) { processing = 1; *args = type_alloc(char *, (char *) 0, sizeof(*args) * (count + 4), &used); if (*args == 0) return 0; (*args)[count++] = strmalloc(name); (*args)[count] = 0; t++; } else {
void flt_init_attr(const char *attr_name) { if (default_attr != 0) free(default_attr); default_attr = strmalloc(attr_name); VERBOSE(3, ("flt_init_attr:%s", attr_name)); }
void flt_init_table(const char *table_name) { if (default_table != 0) free(default_table); default_table = strmalloc(table_name); VERBOSE(3, ("flt_init_table:%s", table_name)); }
/** * Allocates a new text object and associates first_text to text->first. Does not free() before malloc. WARNING: DO NOT USE THIS TO ALLOCATE INITIAL OBJECT. * @param[in,out] first_text - Pointer to a text object * @return Returns the first_text object as a newly allocated object. * @see free_text() */ text* alloc_textFirst(text* first_text) { text* t_text = (text*)malloc(sizeof(text)); t_text->word = strmalloc(); t_text->first = first_text; t_text->next = NULL; return t_text; }
void flt_make_symtab(const char *table_name) { if (*table_name == '\0') { table_name = default_table; } if (!set_symbol_table(table_name)) { CLASS *p; if ((p = typecallocn(CLASS, (size_t) 1)) == 0) { CannotAllocate("flt_make_symtab"); return; } p->name = strmalloc(table_name); if (p->name == 0) { free(p); CannotAllocate("flt_make_symtab"); return; } #if !USE_TSEARCH p->data = typecallocn(KEYWORD *, HASH_LENGTH); if (p->data == 0) { free(p->name); free(p); CannotAllocate("flt_make_symtab"); return; } #endif p->next = classes; classes = p; my_table = p->data; current_class = p; VERBOSE(1, ("flt_make_symtab(%s)", table_name)); /* * Mark all of the standard predefined classes when we first create a * symbol table. Some filters may define their own special classes, * and not all filters use all of these classes, but it's a lot simpler * than putting the definitions into every ".key" file. */ insert_keyword(NAME_ACTION, ATTR_ACTION, 1); insert_keyword(NAME_COMMENT, ATTR_COMMENT, 1); insert_keyword(NAME_ERROR, ATTR_ERROR, 1); insert_keyword(NAME_IDENT, ATTR_IDENT, 1); insert_keyword(NAME_IDENT2, ATTR_IDENT2, 1); insert_keyword(NAME_KEYWORD, ATTR_KEYWORD, 1); insert_keyword(NAME_KEYWRD2, ATTR_KEYWRD2, 1); insert_keyword(NAME_LITERAL, ATTR_LITERAL, 1); insert_keyword(NAME_NUMBER, ATTR_NUMBER, 1); insert_keyword(NAME_PREPROC, ATTR_PREPROC, 1); insert_keyword(NAME_TYPES, ATTR_TYPES, 1); }
char * tempnam(const char *head, const char *tail) { char temp[NFILEN]; char leaf[NFILEN]; return mktemp(strmalloc(pathcat(temp, head, strcat(strcpy(leaf, tail), "XXXXXX")))); }
int main (int argc, const char* argv[]) { //Super important note: //MSVS Doesn't allow declarations to follow statements in a block. //It uses an old C90 ruleset. Support for this was added to C in the C99 standard room alpha; room* rooms = alloc_room(); char* t_str = strmalloc(); FILE* world = fopen("WORLD.DAT","r"); //TODO: Add a parameter parser to allow users to specify different worlds. if (world == NULL) { printf("Could not open WORLD.DAT!\n"); return 1; } load_world(rooms, world); //Load our world data into the rooms /// TEST ROUTINES // /*while (rooms != NULL) //NOTE: Using this will break the room looking { printf(rooms->name); printf("\n"); while (rooms->areas != NULL) { printf("\t"); printf(rooms->areas->name); printf("\n"); printf("\t\t"); printf(rooms->areas->desc); printf("\n"); rooms->areas = rooms->areas->next; } rooms = rooms->next; } if (t_str == "") printf("Empty String"); else if (t_str == NULL) printf("NULL String"); else { itoa(strlen(t_str), t_str, 1); printf(t_str); }*/ printf(rooms->doors->name); gameloop(rooms); printf("User Exited. Press any key to quit."); getchar(); /// END TEST ROUTINES // fclose(world); return 0; }
/** * Allocates a new action object and associates itself to action->first. Does not free() before malloc. USE THIS TO ALLOCATE INITIAL OBJECT. * @return Returns the a newly allocated action object. */ action* alloc_action() //USE THIS FOR THE FIRST INITIALIZATION { action* t_action; t_action = (action*)malloc(sizeof(action)); if (t_action == NULL) return NULL; t_action->name = alloc_text(); t_action->desc = strmalloc(); t_action->first = t_action; t_action->next = NULL; return t_action; }
/** * This gets a line from stdin and allocates it to the specified C String. * @param[in,out] str - Pointer to a C String. * @return Returns str, filled with stdin up to \n */ char* strget (char* str) { char c = 0; str = strmalloc(); printf(">"); //Prompt user for input with 'cursor' while (c != '\n') { c = getchar(); if (c != '\n') str = strccat(str, toupper(c)); } return str; }
static void SetEnv(char **namep, const char *value) { char *newvalue; beginDisplay(); if (*namep == 0 || strcmp(*namep, value)) { if ((newvalue = strmalloc(value)) != 0) { #if OPT_EVAL && OPT_SHELL FreeIfNeeded(*namep); #endif *namep = newvalue; } } endofDisplay(); }
static BI_NODE * new_tags(BI_DATA * a) { BI_NODE *p; beginDisplay(); if ((p = typecalloc(BI_NODE)) != 0) { p->value = *a; if ((BI_KEY(p) = strmalloc(a->bi_key)) == 0) { old_tags(p); p = 0; } } endofDisplay(); return p; }
static BI_NODE * new_elapsed(BI_DATA * a) { BI_NODE *p; beginDisplay(); if ((p = typecalloc(BI_NODE)) != 0) { BI_DATA *q = &(p->value); if ((BI_KEY(p) = strmalloc(a->bi_key)) == 0 || (q->data = typecalloc(ELAPSED_DATA)) == 0) { old_elapsed(p); p = 0; } } endofDisplay(); return p; }
static const char * actual_color(const char *param, int len, int arg) { const char *result; char *s = strmalloc(param); if (len > 0) { /* if not null-terminated, set it now */ s[len] = '\0'; } result = color_of(s, arg); if (*result == 0) result = keyword_attr(s); if (result != 0 && *result != 0 && !is_color(result)) { result = Literal_attr; } free(s); return result; }
static void ExecDefault(char *param) { char *s = skip_ident(param); const char *t = param; const char *attr = Literal_attr; int save = *s; VERBOSE(1, ("ExecDefault(%s)\n", param)); *s = 0; if (!*t) t = NAME_KEYWORD; if (is_class(t)) { free(default_attr); default_attr = strmalloc(t); } if (FltOptions('c')) { attr = actual_color(t, -1, 1); VERBOSE(2, ("actual_color(%s) = %s\n", t, attr)); } *s = (char) save; flt_puts(param, (int) strlen(param), attr); }
static void ExecClass(char *param) { char *t = strmalloc(param); char *s; const char *attr = ""; parse_keyword(t, 1); free(t); t = flt_put_blanks(param); s = skip_ident(t); if (FltOptions('c')) { attr = actual_color(param, (int) (s - param), 1); } else { attr = Ident2_attr; } flt_puts(param, (int) (s - param), attr); if (parse_eqls_ch(&s)) { t = s; s = skip_ident(t); if (FltOptions('c')) { attr = actual_color(t, (int) (s - t), 1); } else { if (*(attr = color_of(t, 0)) == '\0') attr = Action_attr; } flt_puts(t, (int) (s - t), attr); if (parse_eqls_ch(&s)) { flt_puts(s, (int) strlen(s), Literal_attr); } else if (*s) { flt_puts(s, (int) strlen(s), Error_attr); } } else if (*s) { flt_puts(s, (int) strlen(s), Error_attr); } }
int attributeregion(void) { BUFFER *bp = curbp; int status; REGION region; AREGION *arp; if ((status = getregion(bp, ®ion)) == TRUE) { if (apply_attribute()) { if (add_line_attrib(bp, ®ion, regionshape, videoattribute, #if OPT_HYPERTEXT hypercmd #else 0 #endif )) { return TRUE; } /* add new attribute-region */ if ((arp = alloc_AREGION()) == NULL) { return FALSE; } arp->ar_region = region; arp->ar_vattr = videoattribute; /* include ownership */ arp->ar_shape = regionshape; #if OPT_HYPERTEXT arp->ar_hypercmd = 0; if (tb_length(hypercmd) && *tb_values(hypercmd)) { #if OPT_EXTRA_COLOR if (tb_length(hypercmd) > 4 && !memcmp(tb_values(hypercmd), "view ", (size_t) 4)) { int *newVideo = lookup_extra_color(XCOLOR_HYPERTEXT); if (!isEmpty(newVideo)) { arp->ar_vattr = (VIDEO_ATTR) * newVideo; } } #endif arp->ar_hypercmd = strmalloc(tb_values(hypercmd)); tb_init(&hypercmd, 0); } #endif attach_attrib(bp, arp); } else { /* purge attributes in this region */ L_NUM rls = line_no(bp, region.r_orig.l); L_NUM rle = line_no(bp, region.r_end.l); C_NUM ros = region.r_orig.o; C_NUM roe = region.r_end.o; AREGION **pp; AREGION **qq; AREGION *p, *n; int owner; owner = VOWNER(videoattribute); purge_line_attribs(bp, ®ion, regionshape, owner); pp = &(bp->b_attribs); for (p = *pp; p != 0; pp = qq, p = *pp) { L_NUM pls, ple; C_NUM pos, poe; if (interrupted()) return FALSE; qq = &(p->ar_next); if (owner != 0 && owner != VOWNER(p->ar_vattr)) continue; pls = line_no(bp, p->ar_region.r_orig.l); ple = line_no(bp, p->ar_region.r_end.l); pos = p->ar_region.r_orig.o; poe = p->ar_region.r_end.o; /* Earlier the overlapping region check was made based only * on line numbers and so was right only for FULLINES shape * changed it to be correct for rgn_EXACT and rgn_RECTANGLE also * -kuntal 9/13/98 */ /* * check for overlap: * for any shape of region 'p' things are fine as long as * 'region' is above or below it */ if (ple < rls || pls > rle) continue; /* * for rgn_EXACT 'p' region */ if (p->ar_shape == rgn_EXACT) { if (ple == rls && poe - 1 < ros) continue; if (pls == rle && pos > roe) continue; } /* * for rgn_RECTANGLE 'p' region */ if (p->ar_shape == rgn_RECTANGLE) if (poe < ros || pos > roe) continue; /* * FIXME: this removes the whole of an overlapping region; * we really only want to remove the overlapping portion... */ /* * we take care of this fix easily as long as neither of * 'p' or 'region' are rgn_RECTANGLE. we will need to create * at the most one new region in case 'region' is * completely contained within 'p' */ if (p->ar_shape != rgn_RECTANGLE && regionshape != rgn_RECTANGLE) { if ((rls > pls) || (rls == pls && ros > pos)) { p->ar_shape = rgn_EXACT; if ((rle < ple) || (rle == ple && roe < poe)) { /* open a new region */ if ((n = alloc_AREGION()) == NULL) { return FALSE; } n->ar_region = p->ar_region; n->ar_vattr = p->ar_vattr; n->ar_shape = p->ar_shape; #if OPT_HYPERTEXT n->ar_hypercmd = p->ar_hypercmd; #endif n->ar_region.r_orig.l = (region.r_end.l); n->ar_region.r_orig.o = (region.r_end.o); attach_attrib(bp, n); } p->ar_region.r_end.l = (region.r_orig.l); p->ar_region.r_end.o = (region.r_orig.o); curwp->w_flag |= WFHARD; continue; } else if ((rle < ple) || (rle == ple && roe < poe)) { p->ar_region.r_orig.l = (region.r_end.l); p->ar_region.r_orig.o = (region.r_end.o); curwp->w_flag |= WFHARD; continue; } } free_attrib2(bp, pp); qq = pp; } } } return status; }
int main(int argc, char **argv) { struct name_table_entry *name_table = typeCalloc(struct name_table_entry, CAPTABSIZE); HashValue *hash_table = typeCalloc(HashValue, HASHTABSIZE); const char *root_name = ""; int column = 0; int bigstring = 0; int n; char buffer[BUFSIZ]; static const char *typenames[] = {"BOOLEAN", "NUMBER", "STRING"}; short BoolCount = 0; short NumCount = 0; short StrCount = 0; /* The first argument is the column-number (starting with 0). * The second is the root name of the tables to generate. */ if (argc <= 3 || (column = atoi(argv[1])) <= 0 || (column >= MAX_COLUMNS) || *(root_name = argv[2]) == 0 || (bigstring = atoi(argv[3])) < 0 || name_table == 0 || hash_table == 0) { fprintf(stderr, "usage: make_hash column root_name bigstring\n"); exit(EXIT_FAILURE); } /* * Read the table into our arrays. */ for (n = 0; (n < CAPTABSIZE) && fgets(buffer, BUFSIZ, stdin);) { char **list, *nlp = strchr(buffer, '\n'); if (nlp) *nlp = '\0'; list = parse_columns(buffer); if (list == 0) /* blank or comment */ continue; if (column > count_columns(list)) { fprintf(stderr, "expected %d columns, have %d:\n%s\n", column, count_columns(list), buffer); exit(EXIT_FAILURE); } name_table[n].nte_link = -1; /* end-of-hash */ name_table[n].nte_name = strmalloc(list[column]); if (!strcmp(list[2], "bool")) { name_table[n].nte_type = BOOLEAN; name_table[n].nte_index = BoolCount++; } else if (!strcmp(list[2], "num")) { name_table[n].nte_type = NUMBER; name_table[n].nte_index = NumCount++; } else if (!strcmp(list[2], "str")) { name_table[n].nte_type = STRING; name_table[n].nte_index = StrCount++; } else { fprintf(stderr, "Unknown type: %s\n", list[2]); exit(EXIT_FAILURE); } n++; } _nc_make_hash_table(name_table, hash_table); /* * Write the compiled tables to standard output */ if (bigstring) { int len = 0; int nxt; printf("static const char %s_names_text[] = \\\n", root_name); for (n = 0; n < CAPTABSIZE; n++) { nxt = (int) strlen(name_table[n].nte_name) + 5; if (nxt + len > 72) { printf("\\\n"); len = 0; } printf("\"%s\\0\" ", name_table[n].nte_name); len += nxt; } printf(";\n\n"); len = 0; printf("static name_table_data const %s_names_data[] =\n", root_name); printf("{\n"); for (n = 0; n < CAPTABSIZE; n++) { printf("\t{ %15d,\t%10s,\t%3d, %3d }%c\n", len, typenames[name_table[n].nte_type], name_table[n].nte_index, name_table[n].nte_link, n < CAPTABSIZE - 1 ? ',' : ' '); len += (int) strlen(name_table[n].nte_name) + 1; } printf("};\n\n"); printf("static struct name_table_entry *_nc_%s_table = 0;\n\n", root_name); } else { printf("static struct name_table_entry const _nc_%s_table[] =\n", root_name); printf("{\n"); for (n = 0; n < CAPTABSIZE; n++) { _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "\"%s\"", name_table[n].nte_name); printf("\t{ %15s,\t%10s,\t%3d, %3d }%c\n", buffer, typenames[name_table[n].nte_type], name_table[n].nte_index, name_table[n].nte_link, n < CAPTABSIZE - 1 ? ',' : ' '); } printf("};\n\n"); } printf("static const HashValue _nc_%s_hash_table[%d] =\n", root_name, HASHTABSIZE + 1); printf("{\n"); for (n = 0; n < HASHTABSIZE; n++) { printf("\t%3d,\n", hash_table[n]); } printf("\t0\t/* base-of-table */\n"); printf("};\n\n"); printf("#if (BOOLCOUNT!=%d)||(NUMCOUNT!=%d)||(STRCOUNT!=%d)\n", BoolCount, NumCount, StrCount); printf("#error\t--> term.h and comp_captab.c disagree about the <--\n"); printf("#error\t--> numbers of booleans, numbers and/or strings <--\n"); printf("#endif\n\n"); free(hash_table); return EXIT_SUCCESS; }
static void do_filter(FILE *input GCC_UNUSED) { static size_t used; static char *line; char *s; (void) input; /* * Unlike most filters, we make a copy of the attributes, since we will be * manipulating the class symbol table. */ Action_attr = strmalloc(class_attr(NAME_ACTION)); Comment_attr = strmalloc(class_attr(NAME_COMMENT)); Error_attr = strmalloc(class_attr(NAME_ERROR)); Ident_attr = strmalloc(class_attr(NAME_IDENT)); Ident2_attr = strmalloc(class_attr(NAME_IDENT2)); Literal_attr = strmalloc(class_attr(NAME_LITERAL)); zero_or_more = '*'; zero_or_all = '?'; meta_ch = '.'; eqls_ch = ':'; while (flt_gets(&line, &used) != NULL) { int ending = chop_newline(line); s = flt_put_blanks(line);
int allocatePty(int *pty_return, char **line_return) { char name[12], *line = NULL; int pty = -1; const char *name1 = "pqrstuvwxyzPQRST"; char buffer[80]; char *name2 = strcpy(buffer, "0123456789abcdefghijklmnopqrstuv"); const char *p1; char *p2; #if defined(HAVE_GRANTPT) int rc; #ifdef HAVE_POSIX_OPENPT pty = posix_openpt(O_RDWR); #else pty = open("/dev/ptmx", O_RDWR); #endif if (pty < 0) goto bsd; rc = grantpt(pty); if (rc < 0) { close(pty); goto bsd; } rc = unlockpt(pty); if (rc < 0) { close(pty); goto bsd; } line = strmalloc(ptsname(pty)); if (!line) { close(pty); goto bsd; } *pty_return = pty; *line_return = line; return 0; bsd: #elif defined(HAVE_OPENPTY) int rc; char ttydev[80]; /* OpenBSD says at least 16 bytes */ rc = openpty(&pty, &opened_tty, ttydev, NULL, NULL); if (rc < 0) { close(pty); goto bsd; } line = strmalloc(ttydev); if (!line) { close(pty); goto bsd; } *pty_return = pty; *line_return = line; return 0; bsd: #endif /* HAVE_GRANTPT, etc */ strcpy(name, "/dev/pty??"); for (p1 = name1; *p1; p1++) { name[8] = *p1; for (p2 = name2; *p2; p2++) { name[9] = *p2; pty = open(name, O_RDWR); if (pty >= 0) goto found; /* Systems derived from 4.4BSD differ in their pty names, so ENOENT doesn't necessarily imply we're done. */ continue; } } goto bail; found: if ((line = strmalloc(name)) != 0) { line[5] = 't'; fix_pty_perms(line); *pty_return = pty; *line_return = line; return 0; } bail: if (pty >= 0) close(pty); if (line) free(line); return -1; }
char * resolveLocale(const char *locale) { FILE *f; char first[MAX_KEYWORD_LENGTH]; char second[MAX_KEYWORD_LENGTH]; char *resolved = NULL; int rc; int found = 0; TRACE(("resolveLocale(%s)\n", locale)); TRACE(("...looking in %s\n", locale_alias)); f = fopen(locale_alias, "r"); if (f != NULL) { do { rc = parseTwoTokenLine(f, first, second); if (rc < -1) break; if (!strcmp(first, locale)) { resolved = strmalloc(second); found = 1; break; } } while (rc >= 0); if (!found) { if (resolved == NULL) { TRACE(("...not found in %s\n", locale_alias)); resolved = strmalloc(locale); } } fclose(f); } /* * If we did not find the data in the locale.alias file (or as happens with * some, the right column does not appear to specify a valid locale), see * if we can get a better result from the system's locale tables. */ if (!found || !has_encoding(resolved)) { #ifdef HAVE_LANGINFO_CODESET char *improved; if (!ignore_locale && strcmp(locale, "C") && strcmp(locale, "POSIX") && strcmp(locale, "US-ASCII") && (improved = nl_langinfo(CODESET)) != 0) { TRACE(("...nl_langinfo ->%s\n", improved)); free(resolved); resolved = strmalloc(improved); } else #endif if (f == 0 && (fopen(locale_alias, "r") == 0)) { perror(locale_alias); } } TRACE(("...resolveLocale ->%s\n", resolved)); return resolved; }