int main(int argc, char **argv) { int i; t_opt opts; if (my_opts(argc, argv, &opts)) return (-1); if (argc == 1 || only_opts(argc, argv)) read_cat(opts); for (i = 1; i < argc; i++) { if (argv[i] && argv[i][0] != '-') my_cat(argv[i], opts); else if (argv[i][0] == '-' && my_strlen(argv[i]) == 1) read_cat(opts); } return (0); }
size_t my_string_set(my_string_t *obj, const char* str) { size_t len = my_strlen(str); PTR_CHECK_RETURN(obj, "my_string", 0); if ((len+1) > obj->mem_size) { _clear(obj); _expand(obj, len*2); } _set(obj, str); signal_emit(obj->update_signal); return obj->str_len; }
char *return_saisi(char *cmd, t_history **history) { char *str; int indice; indice = -1; if ((str = malloc(my_strlen(cmd) + 1)) == NULL) return (cmd); while (cmd[++indice] != '\0' && indice < SIZE_BUFFER) str[indice] = cmd[indice]; str[indice] = '\0'; str = check_cmd_history(str, history); if (str == NULL) return (cmd); indice = -1; free(cmd); return (str); }
char *my_strdup(char *src) { int i; char *dest; i = 0; if (src == NULL) return (NULL); if ((dest = malloc(my_strlen(src) + 1)) == NULL) return (NULL); while (src[i] != '\0') { dest[i] = src[i]; i += 1; } dest[i] = '\0'; return (dest); }
struct s_stock_par *my_params_to_tab(int ac, char **av) { int i; struct s_stock_par *sulli; sulli = malloc(ac * sizeof(*sulli) + 1); i = 0; while (i < ac) { sulli[i].size_param = my_strlen(av[i]); sulli[i].str = (av[i]); sulli[i].copy = my_strdup(av[i]); sulli[i].tab = my_str_to_wordtab(av[i]); i++; } sulli[i].str = NULL; return (sulli); }
int my_sprintp(va_list list, char *buffer) { unsigned long int nb; int n; nb = va_arg(list, unsigned long int); my_sputstr(buffer, "0x"); my_sput_16(&buffer[my_strlen("0x")], nb, "0123456789abcdef\0"); n = 2; while (nb > 0) { nb = nb / 16; n = n + 1; } buffer[n] = 0; my_revstr(buffer); return (n); }
char* my_evil_str(char* str) { char c; int i; int j; i = 0; j = my_strlen(str) - 1; while(i < j) { c = str[i]; str[i] = str[j]; str[j] = c; i = i + 1; j = j - 1; } return (str); }
/** * Copies C-string 'src' (including the null-byte terminator) into the memory * pointed to by 'dest'. * The strings must not overlap, and 'dest' must be large * enough to contain 'src', *including* the terminating null-byte. * (NOTE: Just as with the real strcpy function, these are PRECONDITIONS, * NOT something your function should check for!) * * Returns 'dest' * * Examples: * const char * str = "Hello World!"; // strlen(str) == 12, but 13 bytes with \0 * char buffer[50]; * printf("%s\n", my_strcpy(buffer, str)); // prints "Hello World!\n" */ char * my_strcpy(char * dest, const char * src) { int i = 0; int j = 0; int k = my_strlen(src) + 1; for(i = 0; i <= k; i++) { dest[i] = src[j]; if(src[j] == '\0') { break; } j++; } return dest; }
void modif_path(t_mysh *ptr, char *str1, char *str2) { int index; index = 0; while (ptr->env[index] != '\0') { if (my_strncmp(ptr->env[index], str1, my_strlen(str1)) == 0) { free(ptr->env[index]); if (str2 != '\0') ptr->env[index] = my_strcat_three(str1, "=", str2); else ptr->env[index] = my_strcat_three(str1, "=", ""); } index++; } }
int my_revstr(char* str) { /*Never said to print so only reverses but doesn't print final string*/ int a, x, b; char c; a = 0; x = my_strlen(str); b = x - 1; while (a < b) { c = str[a]; str[a] = str[b]; str[b] = c; a++; b--; } return x; }
char *my_revstr(char *src) { char *p1; char *p2; char tmp; p1 = src; p2 = p1 + my_strlen(src) - 2; while (p1 < p2) { tmp = *p1; *p1 = *p2; *p2 = tmp; p1++; p2--; } return (src); }
/* * ローマ字変換が不完全だった時に、[aiueo]および"xn"と"xtu"を補って変換して * みる。 */ static void add_dubious_roma(migemo* object, rxgen* rx, unsigned char* query) { int max; int len; char *buf; if (!(len = my_strlen(query))) return; /* * ローマ字の末尾のアレンジのためのバッファを確保する。 * 内訳: オリジナルの長さ、NUL、吃音(xtu)、補足母音([aieuo]) */ max = len + 1 + 3 + 1; buf = malloc(max); if (buf == NULL) return; memcpy(buf, query, len); memset(&buf[len], 0, max - len); if (!strchr(VOWEL_CHARS, buf[len - 1])) { add_dubious_vowels(object, buf, len); /* 未確定単語の長さが2未満か、未確定文字の直前が母音ならば… */ if (len < 2 || strchr(VOWEL_CHARS, buf[len - 2])) { if (buf[len - 1] == 'n') { /* 「ん」を補ってみる */ memcpy(&buf[len - 1], "xn", 2); add_roma(object, buf); } else { /* 「っ{元の子音}{母音}」を補ってみる */ buf[len + 2] = buf[len - 1]; memcpy(&buf[len - 1], "xtu", 3); add_dubious_vowels(object, buf, len + 3); } } } free(buf); }
// NOTE : this function doesn't do full safety checking in the interest of simplicity and speed int numstr::ToInt32(const char *str) { const int BASE = 10; // for now we always assume base is 10 because I never seem to use anything else int result = 0; bool found_first_digit = false; // whether we have found the first digit or not int sign_mult = 1; // 1 if the number is positive, -1 if it's negative for (unsigned int i = 0; i < my_strlen(str); i++) { if (!found_first_digit) { if (is_digit(str[i], BASE)) { found_first_digit = true; } // if it a negative number? else if (str[i] == '-') { sign_mult = -1; } // else it's an unknown character, so we ignore it until we get to the first digit } // note: we do not want this to be an "else if" because the above 'if' needs to flow into this if (found_first_digit) { // make sure we aren't dealing with any non-integers if ((str[i] >= '0') && (str[i] <= '9')) { result *= BASE; result += str[i] - '0'; } // else we've hit unknown characters so we're done else { break; } } } return result * sign_mult; }
void add_sign(char **str, char sign) { char *result; char *temp; int counter; counter = 0; temp = *str; result = malloc(my_strlen(temp) + 1); result[0] = sign; while (temp[counter]) { result[counter + 1] = temp[counter]; counter++; } result[counter + 1] = '\0'; free (*str); *str = result; }
/* ** Liberates all the elements that has been malloced for a client */ void free_client(t_client *c) { t_list *l_req; t_request *req; if (close(c->socket) == -1) xwrite(1, FD_CLOSING_ERROR, my_strlen(FD_CLOSING_ERROR)); free(c->team_name); free(c->to_send); l_req = c->requests; while (l_req) { req = l_req->data; free_request(req); l_req = l_req->next; } my_free_all_list_struct(c->requests); free(c); }
char *my_initialize_str(char *src) { int i; int len; char c; char *dest; i = 0; len = my_strlen(src); c = ' '; dest = my_strdup(src); while (i < len) { dest[i] = c; c = c + 1; i = i + 1; } return (dest); }
int my_putnbr_base_rec(int nb, char *base) { int c; c = my_strlen(base); if (nb < 0) { my_putchar('-'); nb = -nb; } if (nb >= c) { my_putnbr_base_rec(nb / c, base); my_putnbr_base_rec(nb % c, base); } else my_putchar(base[c]); return (0); }
char *get_term_name_cpy(char *str) { char *name; int i; i = 5; if (!(name = gbgc_calloc(sizeof(char) * (my_strlen(str) - i + 1)))) { my_perror("malloc failed"); return (NULL); } while (str[i]) { name[i - 5] = str[i]; i++; } name[i - 5] = 0; return (name); }
char *copy_ab(char *a) { char *out; int i; int max; max = my_strlen(a); i = 0; out = malloc(max * sizeof(char)); if (out == NULL || a == NULL) return (NULL); while (i < max) { out[i] = a[i]; i = i + 1; } out[i] = 0; return (out); }
int my_getnbr(char *nbr) { int n; int i; int res; n = 1; if (check_nbr(nbr) == -1) return (-1); res = 0; i = my_strlen(nbr) - 1; while (i >= 0) { res += n * (nbr[i] - 48); n = n * 10; i--; } return (res); }
//*************************my_atk_text_delete_text******************* void my_atk_text_delete_text(AtkEditableText* text, gint start_pos, gint end_pos) { MyAtkText* myAtkText = (MyAtkText*)text; gchar *str = myAtkText->str; gint strlen_old = my_strlen(str); if(start_pos < 0 || end_pos > strlen_old || start_pos >= end_pos )return; if(strlen_old != end_pos) memmove(str + start_pos, str + end_pos, strlen_old - end_pos); str[start_pos - end_pos + strlen_old] = '\0'; correct_selections_after_delete(myAtkText, start_pos, end_pos - start_pos); correct_attributes_after_delete(myAtkText, start_pos, end_pos - start_pos); correct_caret_after_delete(myAtkText, start_pos, end_pos - start_pos); g_signal_emit_by_name(text, "text-changed::delete", start_pos, end_pos - start_pos); g_signal_emit_by_name(text, "text-selection-changed"); g_signal_emit_by_name(text, "text-attributes-changed"); g_signal_emit_by_name(text, "text-caret-moved", myAtkText->caret_offset); }
char *my_strndup(char *src, int lim) { char *result; register unsigned int i; register unsigned int len; len = my_strlen(src); if (lim < len) len = lim; i = 0; result = (char *)malloc_or_die(len + 1); while (i < len) { result[i] = src[i]; i++; } result[len] = '\0'; return (result); }
static char *my_str_new_line(t_str *str) { char *new_line; t_uint len; t_uint i; if (str == NULL) return (NULL); len = my_strlen(str->str); i = 0; while (str->prev != NULL) { i++; str = str->prev; } if ((new_line = my_malloc(sizeof(char) * (i * BUF + len + 1))) == NULL) return (NULL); return (new_line); }
char *ajoute_moins(char *base, char *operators, char *expr) { char *new_expr; int len; len = my_strlen(expr); if ((len == 1) && (expr[0] == base[0])) return (expr); if ((new_expr = malloc(sizeof(*new_expr) * len + 2)) == NULL) exit(-1); my_revstr(expr); my_strcpy(new_expr, expr); new_expr[len] = operators[OP_NEG_IDX]; new_expr[len + 1] = '\0'; my_revstr(new_expr); free(expr); return (new_expr); }
char *my_strcat(char *dest, char *src) { int i; int x; i = 0; x = my_strlen(dest); if (src != NULL) { while (src[i] != '\0') { dest[x] = src[i]; x = x + 1; i = i + 1; } dest[x] = '\0'; } return (dest); }
t_letter *get_message(char *message) { t_letter *msg; int i; i = 0; if ((msg = malloc(sizeof(*msg) * my_strlen(message) + 1)) == NULL) return (NULL); while (*message) { msg[i].pos = get_position(*message, " abcdefghijqlmnopqrstuvwxyz"); msg[i].ascii = (int)*message; msg[i].f = *message; message++; i++; } msg[i].pos = -1; return (msg); }
bool change_level_simp(t_tetris *tetris, char *str) { int i; char *tmp; if ((tmp = malloc(sizeof(char) * (my_strlen(str) + 1))) == NULL) return (false); i = -1; while (str[++i] != '\0' && str) { if (str[i] < '0' || str[i] > '9') wrong_options(str); tmp[i] = str[i]; } tmp[i] = '\0'; tetris->options->level = my_getnbr(tmp); free(tmp); return (true); }
void gcheck_msg(t_data *data, char *msg) { if (msg[1] == 'a') g_check_msg_1(data, msg); else if (msg[1] == 'r') g_check_msg_2(data, msg); else if (msg[1] == 'z') { g_check_msg_3(data); } else if (msg[1] == 's') { write(1, "TO FIXXXXXXX Setting status for ", 32); write(1, msg, my_strlen(msg)); write(1, "\n", 1); } else write(1, "ready\n", 6); }
char *my_strncat(const char *s1, char *s2, int n) { int i; int j; char *ptr; j = 0; i = my_strlen(s1) + n; if ((ptr = my_xmalloc((i + 1) * sizeof(char))) == NULL) return (NULL); ptr[i] = 0; i = 0; while (s1 && s1[j]) ptr[i++] = s1[j++]; j = 0; while ((j < n) && (s2)) ptr[i++] = s2[j++]; return (ptr); }
int my_unsetenv(char **env, char *name) { int i; int change; i = 0; change = 0; while (env[i]) { if (my_strncmp(env[i], name, my_strlen(name) - 1) == 0) { change = 1; } if (change == 1) env[i] = env[i + 1]; i++; } return (1); }